开发者

How to convert string to sentence case in C#?

开发者 https://www.devze.com 2023-02-03 19:51 出处:网络
How can I convert a string to a sentence case? I don\'t want to convert to title case. My re开发者_如何转开发quirement is to convert the string to sentence case.In C# you do this:

How can I convert a string to a sentence case?

I don't want to convert to title case. My re开发者_如何转开发quirement is to convert the string to sentence case.


In C# you do this:

static string UppercaseFirst(string s)
{
    // Check for empty string.
    if (string.IsNullOrEmpty(s))
    {
        return string.Empty;
    }
    // Return char and concat substring.
    return char.ToUpper(s[0]) + s.Substring(1);
}

In CSS you could do the following (if your browser supports it)

#mytitle:first-letter 
{
text-transform:capitalize;
}


I would vonvert the whole string to smallcase and then convert the first letter to upper.Heres an example in C#

string s = "SOME STRING";
System.Text.StringBuilder sb = new System.Text.StringBuilder(s);
s.ToLower();
s.ToUpper(s.Substring(0, 1));
0

精彩评论

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