开发者

How do I change a string of text into lower case except the first letter

开发者 https://www.devze.com 2022-12-11 10:01 出处:网络
How开发者_如何学编程 do I change a string of text into lower case except the first letterString value = \"HELLO\";

How开发者_如何学编程 do I change a string of text into lower case except the first letter


String value = "HELLO";
value = value.Substring(0, 1).ToUpper() + value.Substring(1).ToLower();


If the first letter should be upper-case (not mentioned in the question):

public static string ToLowerExceptFirstLetter(string value)
{
  if (string.IsNullOrEmpty(value))
    return value;

  if (value.Length > 1)
    return value.Substring(0, 1).ToUpper() + value.Substring(1).ToLower();
  else
    return value.ToUpper();
}

If the first letter should not be upper-cased automatically (or is already upper-case):

public static string ToLowerExceptFirstLetter(string value)
{
  if (value == null || value.Length <= 1)
    return value;

  return value.Substring(0, 1) + value.Substring(1).ToLower();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消