Here is a simple static class method that takes a camel case (or camel back) formatted string and inserts a space whenever a capital letter is found (except the first one, of course), then returns the result.
There is no intended support for globalization or special cases, though this would be easy add. This was written to inspect public properties through reflection and create a readable label (By non developers) for an edit field.
While it is really simple, you might find it useful. Additionally, it demonstrates how to perform character functions previously available in VB. I don't miss VB, this was easy!
public class StringManipulator
{
public static string SpaceMyCamelCase(string camelCaseValue)
StringBuilder sbReturn = new StringBuilder();
byte[] byteAry = Encoding.ASCII.GetBytes(camelCaseValue);
sbReturn.Append(Convert.ToChar(byteAry[0]));
for(int ic=1;ic<byteAry.Length;ic++)
int iCurrChar = (int)byteAry[ic];
// char key //A:65//Z:90//a:97//z:122//0:49//1:57
if( 64<iCurrChar&&iCurrChar<91 ) sbReturn.Append(" ");
sbReturn.Append(Convert.ToChar(byteAry[ic]));
}
return sbReturn.ToString();
a call like:
StringManipulator.SpaceMyCamelCase(
results in:
"Is A Cool Feature"
p.s. If you think of or have seen a better, easier or more globally concious method, let me know!
Remember Me
Theme design by Jelle Druyts
Pick a theme: BlogXP calmBlue Candid Blue dasBlog Discreet Blog Blue Elegante essence Just Html Mono Movable Radio Blue Movable Radio Heat orangeCream Portal Project84 Slate Sound Waves Tricoleur