|
-
January 18th, 2011, 11:35 AM
#1
Cleaning up code with Regular Expressions
I am terrible at knowing regular expressions very well so mostly I find examples then try to use them, however my code usually ends up being really ugly even though it works.
Code:
string classifications = LineNode.InnerText;
//Makes This_TypeOfStringIsLong > This_Type Of String Is Long
string spaced = Regex.Replace(classifications, @"([a-z])([A-Z])", @"$1 $2", RegexOptions.None);
//Makes This_Type Of String Is Long > This_Type,Of,String,Is,Long
string modded = spaced.Replace(" ", ",");
//Makes This_Type,Of,String,Is,Long > This Type,Of,String,Is,Long
string again = modded.Replace("_", " ");
string[] LineArray = again.Split(',');
Is there a simple shorter way of doing this?
we begin with a string like "This_TypeOfStringIsLong" has to be parsed out by each Capital Word, then if there is a _ make a space, but its original word has to be treated as one
example Blue_SkyDarkNightOwl > Blue Sky, Dark, Night, Owl
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|