Convert (Change) string to Title Case in C# and VB.Net

pandeygolu4200
 
on Jun 06, 2022 03:26 AM
256 Views

I want to store my data in title case in my store procedure, how can i save my parameter in title case while inserting.

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Jun 06, 2022 03:30 AM

Hi pandeygolu420...,

Before passing the parameter to the procedure you need to convert the text to title case.

So you need to use TextInfo class ToTitleCase method.

Refer below code.

Code

C#

string title = "welcome to aspsnippets";
title = (new CultureInfo("en-US", false).TextInfo).ToTitleCase(title);

VB.Net

Dim title As String = "welcome to aspsnippets"
title = (New CultureInfo("en-US", False).TextInfo).ToTitleCase(title)

Output

Welcome To Aspsnippets