Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / August 2007

Tip: Looking for answers? Try searching our database.

Simple (regex?) string manipulation

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Marc Gravell - 15 Aug 2007 14:28 GMT
Blonde moment...

Before I try and do it a harder way, can anybody remind me how to get
the desired from the following? I simply want to split
"aTypicalCamelCasePropertyName" into a "a Typical Camel Case Property
Name" (fully expanding upper-case blocks as the simplest answer to the
ambiguity)

Console.WriteLine(Regex.Replace(
           @"testInputOfWhatIWantUPPERS",
           @"([a-zA-Z])([A-Z])",
           @"$1 $2"));

I want: "test Input Of What I Want U P P E R S"
I currently get: "test Input Of What IWant UP PE RS" - i.e. the upper-
case is getting consumed each time.

Any offers?

Marc
Jesse Houwing - 15 Aug 2007 14:38 GMT
Hello Marc,

> Blonde moment...
>
[quoted text clipped - 14 lines]
>
> Marc

Make the first group a Look behind, so that is is not part of the match.
Then only insert a space before the found character like so:

> Console.WriteLine(Regex.Replace(
> @"testInputOfWhatIWantUPPERS",
> @"(?<=[a-zA-Z])([A-Z])",
> @" $1"));

--
Jesse Houwing
jesse.houwing at sogeti.nl
Marc Gravell - 15 Aug 2007 14:57 GMT
Perfect; much obliged

Marc

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.