我有一个字符串,该字符串已转换为TextInfo.ToTitleCase并删除了下划线并将该字符串连接在一起。现在,我需要将字符串中的第一个字符和只有第一个字符更改为小写,并且由于某种原因,我不知道如何完成此操作。在此先感谢您的帮助。
class Program
{
static void Main(string[] args)
{
string functionName = "zebulans_nightmare";
TextInfo txtInfo = new CultureInfo("en-us", false).TextInfo;
functionName = txtInfo.ToTitleCase(functionName).Replace('_', ' ').Replace(" ", String.Empty);
Console.Out.WriteLine(functionName);
Console.ReadLine();
}
}
结果:斑马梦ight
预期结果:斑马梦ight
更新:
class Program
{
static void Main(string[] args)
{
string functionName = "zebulans_nightmare";
TextInfo txtInfo = new CultureInfo("en-us", false).TextInfo;
functionName = txtInfo.ToTitleCase(functionName).Replace("_", string.Empty).Replace(" ", string.Empty);
functionName = $"{functionName.First().ToString().ToLowerInvariant()}{functionName.Substring(1)}";
Console.Out.WriteLine(functionName);
Console.ReadLine();
}
}
产生所需的输出
您只需要降低数组中的第一个字符。看到这个答案
Char.ToLowerInvariant(name[0]) + name.Substring(1)
附带说明,看到要删除空格时,可以将下划线替换为空字符串。
.Replace("_", string.Empty)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句