المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Regex getting special characters



C# Programming
10-28-2012, 09:10 PM
I have a string like:
string s1 = "dog().Cat(\"Happy\")"; I want to:
1) count the number of round brackets '(', I expect as result 2
2) get the text inside, I expect "\"Happy"\", which appear in console output as "Happy"
No idea for 1. I try the following for 2
string k = Regex.Match(s1,@"\((\w+)\)").Groups[1].Value; But It fails in understanding the \" character
Any Idea?