Proper case is just capitalizing the first character of each proper name in a string.
Change "KEVIN PIRKL" to "Kevin Pirkl"
It was really bugging me seeing code from lots of people that did Proper Case of name. I would thing that you could use a Regular expression in C# to do it and after some poking around here's the code worked out.
It is not so bad when you get right down to it..
public static string GetUserName()
{
string usrname = "";
Intel.Utilities.UserData ud = new Intel.Utilities.UserData(true);
if ( ud.LoginId != "")
usrname = ud.FirstName + " " + ud.LastName;
MatchEvaluator myev = new MatchEvaluator(upperit);
usrname = Regex.Replace(usrname.ToLower(),"(^.?|\s.?)",myev);
return usrname;
}
private static string upperit(Match param)
{
return param.Value.ToUpper();
}
Here is an example of some code in JavaScript that does the same
Proper Case JavaScript Function on Code Project
// proper case function (JScript 5.5+)
function toProperCase(s)
{
return s.toLowerCase().replace(/^(.)|s(.)/g,
function($1) { return $1.toUpperCase(); });
}
Hope this helps
No comments:
Post a Comment