Reputation: 4661
I have a large list of text in c# that in want to use as an enum list. For example:
Zone Status Message
Zones Snapshot Message
Partition Status Message
Partitions Snapshot Message
Supported transition message flags
System Status Message
X-10 Message Received
Log Event Message
Keypad Message Received
Now I want to use the find and replace dialog in visual studio to add underscores in all the words instead of a space, for example
Zone_Status_Message
Zones_Snapshot_Message
How can I achieve this using regex or wildcard? This would really save me a lot of time.
Thanks in advance.
EDIT:
The words can also have spaces and the front and back, due to a poorly formatted source document where I get the text from. So the underscore should only be added when the space is between 2 words.
Upvotes: 1
Views: 3821
Reputation: 13641
In VS 2010, to replace a space between alphanumeric characters you could use
Find What {:a} {:a}
Replace With \1_\2
Make sure Use Regular expressions
is checked.
Replace All
Upvotes: 1
Reputation: 336378
If you only want to match spaces between alphanumeric words, search for > <
and replace all with _
.
In VS regexes (until version 2010), >
means "the position at the end of a word" and <
means "the position at the start of a word".
In VS 2012 and up, that regex could be written as \b \b
.
Upvotes: 1