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.
string content = "VCA Event is$EventName$$ShelterName$
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$
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
your solution is perfectly worked.but for one scenario
if string content = "VCA Event is$EventName$Name$ShelterN ame$ 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
if string content = "VCA Event is$EventName$Name$ShelterN
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
*/
ASKER
yeah it worked...Thanks for helping me out..........Reallly appriciate your help..
please clarify...