.NET method to convert a string to sentence case

后端 未结 9 1742
一向
一向 2020-11-30 09:47

I\'m looking for a function to convert a string of text that is in UpperCase to SentenceCase. All the examples I can find turn the text into TitleCase.

<
9条回答
  •  我在风中等你
    2020-11-30 10:23

    This works for me.

    /// 
    /// Converts a string to sentence case.
    /// 
    /// The string to convert.
    /// A string
    public static string SentenceCase(string input)
    {
        if (input.Length < 1)
            return input;
    
        string sentence = input.ToLower();
        return sentence[0].ToString().ToUpper() +
           sentence.Substring(1);
    }
    

提交回复
热议问题