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();
}
精彩评论