Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Contributor
4963 Points
1036 Posts
May 09, 2008 08:40 AM|LINK
I would try with regular expressions (if you don't know ii, I highly recommend to learn it, there are excellent tutorials on the web)
string test = "PascalCaseSomethingMatchAlsoASingleCharacter"; Response.Write( test + "<br />"); System.Text.RegularExpressions.Regex pattern = new System.Text.RegularExpressions.Regex( "[A-Z][a-z]*" ); System.Text.RegularExpressions.Match result = pattern.Match( test ); while( result.Success ) { Response.Write( result.Value + "<br />" ); result = result.NextMatch( ); }
Anyway there could be problematic identifiers:
What about this: "thisstartwithcamelcaseWhatIsNow", you can use this pattern for this for example: "([a-z]+|[A-Z][a-z]*)"
And what about his: "ThisContainsSomeIDHowToTreatThis", you can split this several ways: Some, ID, How or Some, IDH, ow [:D]
stmarti
Contributor
4963 Points
1036 Posts
Re: Splitting strings with Pascal notation.
May 09, 2008 08:40 AM|LINK
I would try with regular expressions (if you don't know ii, I highly recommend to learn it, there are excellent tutorials on the web)
string test = "PascalCaseSomethingMatchAlsoASingleCharacter"; Response.Write( test + "<br />"); System.Text.RegularExpressions.Regex pattern = new System.Text.RegularExpressions.Regex( "[A-Z][a-z]*" ); System.Text.RegularExpressions.Match result = pattern.Match( test ); while( result.Success ) { Response.Write( result.Value + "<br />" ); result = result.NextMatch( ); }Anyway there could be problematic identifiers:
What about this: "thisstartwithcamelcaseWhatIsNow", you can use this pattern for this for example: "([a-z]+|[A-Z][a-z]*)"
And what about his: "ThisContainsSomeIDHowToTreatThis", you can split this several ways: Some, ID, How or Some, IDH, ow [:D]