Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extracting a sub-string in C#

Tags:

c#

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 string

s1="here there (hi)";

How can I get

s2="hi";

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

like image 292
hero Avatar asked Dec 18 '22 02:12

hero


1 Answers

string s1 = "abc (hi)";
string s2 = s1.Substring(s1.LastIndexOf("(") + 1, s1.LastIndexOf(")") - s1.LastIndexOf("(") - 1);
like image 127
thelost Avatar answered Jan 05 '23 19:01

thelost