Search This Blog

Monday 23 September 2019

Convert a string to Title Case in Xamarin.Forms

Create the ToTitle method with the following code.

public static string ToTitle(string data)
{
    if (!string.IsNullOrEmpty(data))
    {
        TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;
        return string.Format(textInfo.ToTitleCase(data.ToLower()));
    }

    return data;
}

Now use this method on any page to convert any string into Title case.

string msg = "title test string";
Console.WriteLine(msg.ToTitle());


3 comments:

Popular Posts