Jak*_*ake 30
正则表达式听起来最好:
string input = "Test_StringForYou";
string replaced = Regex.Replace(input, @"(?<!_)([A-Z])", "_$1");
Console.WriteLine(replaced);
Run Code Online (Sandbox Code Playgroud)
输出:_Test_String_For_You
一定要添加一个 using System.Text.RegularExpressions;