I\'ve been tinkering with small functions on my own time, trying to find ways to refactor them (I recently read Martin Fowler\'s book Refactoring: Improving the Design of Ex
I know what they say about RegEx, use it to solve a problem and now you have two problems, but I remain a fan, Just for grins, here is a RegEx version. RegEx, with a little initiation is easy to read, less code, and lets you easily snap in additional delimiters (as I did with the comma).
s1 = MakeNiceString( "LookOut,Momma,There'sAWhiteBoatComingUpTheRiver" ) );
private string MakeNiceString( string input )
{
StringBuilder sb = new StringBuilder( input );
int Incrementer = 0;
MatchCollection mc;
const string SPACE = " ";
mc = Regex.Matches( input, "[A-Z|,]" );
foreach ( Match m in mc )
{
if ( m.Index > 0 )
{
sb.Insert( m.Index + Incrementer, SPACE );
Incrementer++;
}
}
return sb.ToString().TrimEnd();
}