Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Proper function
Message
 
To
16/06/2006 12:54:33
Jerry Tovar
Dana Corporation Dana It
Maumee, Ohio, United States
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Environment versions
Environment:
C# 2.0
Miscellaneous
Thread ID:
01129595
Message ID:
01131420
Views:
9
>Is there a Proper() function in C#, similar to the VFP9 PROPER() function, which will capitalize the first letter in each word and make the rest lower case?
>
>Thanks,
>
>Jerry

Jerry,
I don't think I have seen such function in .NET, but here is how the people that created the Visual Foxpro Toolkit for .NET converted the PROPER function:
public static string Proper(string cString)
{
	//Create the StringBuilder
	StringBuilder sb = new StringBuilder(cString);

	int i,j = 0 ;
	int nLength = cString.Length ;

	for ( i = 0 ; i < nLength; i++)
	{
		//look for a blank space and once found make the next character to uppercase
		if ((i== 0) || (char.IsWhiteSpace(cString[i])))
		{
			//Handle the first character differently
			if( i==0 ) {j=i;}
			else  {j=i+1;}

			//Make the next character uppercase and update the stringBuilder
			sb.Remove(j, 1);
			sb.Insert(j, Char.ToUpper(cString[j]));
			}
		}
	return sb.ToString();
}
If you haven't already I recomend checking the Visual Foxpro Toolkit for .NET (http://foxcentral.net/microsoft/VFPToolkitNET.htm).

HTH,
Einar
Semper ubi sub ubi.
Previous
Reply
Map
View

Click here to load this message in the networking platform