1

我想自动将字符串中的第一个字符大写,就像我通过键盘输入“john”一样,保存在变量中的数据将是“John”。那么如何将 32 添加到字符串的第一个字符以使其大写呢?请给我指路。谢谢。

4

2 回答 2

1

您应该自己编写它,例如

Console.WriteLine(CapitalizeFirst("cihan"));

private string CapitalizeFirst(string s)
{
   if (string.IsNullOrEmpty(s))
   {
       return string.Empty;
   }
   return char.ToUpper(s[0]) + s.Substring(1);
} 

然后输出将是 Cihan

于 2015-01-09T14:16:33.613 回答
0

$("input").keyup(function(event){ if(event.ctrlKey || event.altKey){ return; }else{ $(this).val($(this).val().toUpperCase()); str = $(this).val(); str = str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}); $(this).val(str); } });

于 2015-03-30T06:09:12.030 回答