Ahm*_*low 1 c# string uppercase
如何找到现有字符串的大写字母并在每个字母前添加 (-)?
string inputStr = "fhkSGJndjHkjsdA";
string outputStr = String.Concat(inputStr.Where(x => Char.IsUpper(x)));
Console.WriteLine(outputStr);
Console.ReadKey();
Run Code Online (Sandbox Code Playgroud)
此代码找到大写字母并将它们打印在屏幕上,但我希望它打印:
fhk-S-G-Jndj-Hkjsd-A
我怎样才能做到这一点?
我认为使用 RegEx 会容易得多:
string outputStr = Regex.Replace(inputStr, "([A-Z])", "-$1");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
90 次 |
| 最近记录: |