473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

ToPascalCase() ?


Ok, maybe thats not the best name for a method, but I'm looking for
something along the lines of ToUpper() or ToLower()

If I have an input like
john smith
or
johN smitH

...

Is there a way to cleanly make it

John Smith ?

Normally, space would be the delimeter, but knowing how to do it with any
delimiter would be cool too.

marY;jonEs
would be
Mary;Jones
Thanks for any ideas. I don't have the brainpower today to search. Aka, I
need a memorial day weekend break.

...
-----------------------------
Sloan
http://spaces.msn.com/sholliday/
May 26 '06 #1
3 3340
This works:

private string ToPascalCase(string input, char separator)
{
StringBuilder sb = new StringBuilder();
string[] parts = input.Split(separator);
foreach (string part in parts)
{
if (part.Length > 0)
{
sb.Append(Char.ToUpper(part[0]));
if (part.Length > 1)
sb.Append(part.Substring(1).ToLower());
}
sb.Append(separator);
}
sb.Remove(sb.Length - 1, 1);
return sb.ToString();
}

Might not be the best way of doing it though...

/claes

"sloan" <sl***@ipass.net> wrote in message
news:Ox**************@TK2MSFTNGP03.phx.gbl...

Ok, maybe thats not the best name for a method, but I'm looking for
something along the lines of ToUpper() or ToLower()

If I have an input like
john smith
or
johN smitH

..

Is there a way to cleanly make it

John Smith ?

Normally, space would be the delimeter, but knowing how to do it with any
delimiter would be cool too.

marY;jonEs
would be
Mary;Jones
Thanks for any ideas. I don't have the brainpower today to search. Aka,
I
need a memorial day weekend break.

..
-----------------------------
Sloan
http://spaces.msn.com/sholliday/

May 26 '06 #2
you might try something like

// Capitalize A String
public static string Capitalize (string Text)
{
return
System.Globalization.CultureInfo.InvariantCulture. TextInfo.ToTitleCase
(Text) ;
}

"sloan" <sl***@ipass.net> wrote in message
news:Ox**************@TK2MSFTNGP03.phx.gbl...

Ok, maybe thats not the best name for a method, but I'm looking for
something along the lines of ToUpper() or ToLower()

If I have an input like
john smith
or
johN smitH

..

Is there a way to cleanly make it

John Smith ?

Normally, space would be the delimeter, but knowing how to do it with any
delimiter would be cool too.

marY;jonEs
would be
Mary;Jones
Thanks for any ideas. I don't have the brainpower today to search. Aka,
I
need a memorial day weekend break.

..
-----------------------------
Sloan
http://spaces.msn.com/sholliday/

May 26 '06 #3
That's the ticket!

http://msdn2.microsoft.com/en-us/lib...textinfo.totit
lecase.aspx

Thanks all...
"Luc E. Mistiaen" <lu**********@advalvas.be.no.spam> wrote in message
news:OR**************@TK2MSFTNGP04.phx.gbl...
you might try something like

// Capitalize A String
public static string Capitalize (string Text)
{
return
System.Globalization.CultureInfo.InvariantCulture. TextInfo.ToTitleCase
(Text) ;
}

"sloan" <sl***@ipass.net> wrote in message
news:Ox**************@TK2MSFTNGP03.phx.gbl...

Ok, maybe thats not the best name for a method, but I'm looking for
something along the lines of ToUpper() or ToLower()

If I have an input like
john smith
or
johN smitH

..

Is there a way to cleanly make it

John Smith ?

Normally, space would be the delimeter, but knowing how to do it with any delimiter would be cool too.

marY;jonEs
would be
Mary;Jones
Thanks for any ideas. I don't have the brainpower today to search. Aka, I
need a memorial day weekend break.

..
-----------------------------
Sloan
http://spaces.msn.com/sholliday/


May 27 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.