Link to home
Start Free TrialLog in
Avatar of itinfo7
itinfo7

asked on

Get the word between Special character

I have string like this for example

string content = "VCA Event is$EventName$$ShelterName$ will be in Texas Hospital";

I want character between "$". and I am not sure how many words I have with "$".

It could be 1: "VCA Event is$EventName$ will be in Texas Hospital";
IT could be 2:"VCA Event is$EventName$$ShelterName$ will be in Texas Hospital";
It could be any numbers and the string between two "$" is also not fixed it could be any character.

Please give me some soultion of this.I am stuck in this one.
Avatar of BuggyCoder
BuggyCoder
Flag of India image

do you want the words between exactly two $ signs, or do you want all the words in the string except dollar sign....

please clarify...
ASKER CERTIFIED SOLUTION
Avatar of wdosanjos
wdosanjos
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of itinfo7
itinfo7

ASKER

your solution is perfectly worked.but for one scenario
 if string content = "VCA Event is$EventName$Name$ShelterName$ will be in Texas Hospital";

In this can I don't want Name but Name is in between $$ it's giving me. three keywords
EventName,Name,helterName
OK.  Please update the code as follows:
var rx = new Regex(@"\$([^\$]+?)\$");
string content = "VCA Event is$EventName$Name$ShelterName$ will be in Texas Hospital";

string[] keywords = rx.Matches(content).Cast<Match>().Select( _ => _.Groups[1].Value).ToArray();

/* Output

EventName
ShelterName

*/

Open in new window

Avatar of itinfo7

ASKER

yeah it worked...Thanks for helping me out..........Reallly appriciate your help..