I am new to c# programming and I want to ask a question.
How can I get the value in () and store it in another string. example:
I have strings1="here there (hi)";
How can I get
开发者_如何学Cs2="hi";
the ()
will always be at the end of the sentence (never at first or in between).
string s1 = "abc (hi)";
string s2 = s1.Substring(s1.LastIndexOf("(") + 1, s1.LastIndexOf(")") - s1.LastIndexOf("(") - 1);
string s2 = s1.Substring(s1.LastIndexOf("(") + 1, s1.LastIndexOf(")") - s1.LastIndexOf("(") - 1);
string e1 = "here there (hi)";
//Extraction
string s2 = e1.Substring(e1.IndexOf("(")+1, (e1.LastIndexOf(")") - e1.IndexOf("("))-1);
精彩评论