In VB 6.0, we use StrConv() function to convert to proper case.
1 Dim stringVariable as String
2 stringVariable = "hello world"
3 stringVariable = StrConv(stringVariable,vbProperCase)
4 Debug.Print stringvariable 'Prints Hello World
In VB.Net, we could still use the same function, use the Microsoft.VisualBasic Namespace.
1 Dim stringVariable as String
2 stringVariable = "hello world"
3 stringVariable = StrConv(s,VbStrConv.ProperCase)
4 System.Diagnostics.Debug.Writeln (stringvariable) 'Prints Hello World
If you are using c#, you could use the same technique, only point to note is that you will need to pass the locale ID to the StrConv() function (optional param is not possible)
1 string stringVariable = "hello world";
2 stringVariable = Strings.StrConv(s,VbStrConv.ProperCase,new CultureInfo("en-us").LCID);
3 System.Diagnostics.Debug.Writeln (stringvariable); //Prints Hello World
A little more elegant solution is to use TextInfo class to achieve the same.
C# code is shown below,
1 string stringVariable = "hello world";
2 stringVariable = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(Input.ToLower());
3 System.Diagnostics.Debug.Writeln (stringvariable); //Prints Hello World
Happy Coding!
Cheers!
1 comments:
Genial dispatch and this post helped me alot in my college assignement. Thank you seeking your information.
Post a Comment