Extracting a substring in C #

I am new to C # programming and I want to ask a question.

How can I get the value in () and save it on another line. Example:
I have a line

s1="here there (hi)"; 

How can I get

 s2="hi"; 

() will always be at the end of a sentence (never at first or between). A.

+4
source share
3 answers
 string s1 = "abc (hi)"; string s2 = s1.Substring(s1.LastIndexOf("(") + 1, s1.LastIndexOf(")") - s1.LastIndexOf("(") - 1); 
+8
source
 string s2 = s1.Substring(s1.LastIndexOf("(") + 1, s1.LastIndexOf(")") - s1.LastIndexOf("(") - 1); 
+2
source
  string e1 = "here there (hi)"; //Extraction string s2 = e1.Substring(e1.IndexOf("(")+1, (e1.LastIndexOf(")") - e1.IndexOf("("))-1); 
+2
source

Source: https://habr.com/ru/post/1303924/


All Articles