string
input =
"
soap(999)"
;
String
SID = input.Remove(input.IndexOf(
'
)'
)).Substring(input.IndexOf(
'
('
) +
1
);
output: 999
This is fine, But my need is
String
input =
"
soap(small)(999)"
;
If my string is like this means,I am not able to retriev id from string "999"
Note: In my String always "id" will be in last position only
Thanks in Advance.
It is not clear what do you mean by "between two brackets". You might not think about it, but "(small)(999)" is another kind of match, but you probably need "(small)" or "(999)", which is called a lazy pattern.
You can find all kinds of matches using Regular Expressions. For example:
using
System.Text.RegularExpressions;
string
sampleInput =
"
soap(small)(999)"
;
Regex regex =
new
Regex(
@"
\(.*?\)"
);
MatchCollection matches = regex.Matches(sampleInput);
int
count = matches.Count;
string
s0 = matches[0].Result;
string
s1 = matches[1].Result;
But if you use
Regex regex =
new
Regex(
@"
\(.*\)"
);you will get only one match "(small)(999)".
http://msdn.microsoft.com/en-us/library/hs600312.aspx
[
^
],
http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex.aspx
[
^
],
http://en.wikipedia.org/wiki/Regular_expression
[
^
].
Read the question carefully.
Understand that English isn't everyone's first language so be lenient of bad
spelling and grammar.
If a question is poorly phrased then either ask for clarification, ignore it, or
edit the question
and fix the problem. Insults are not welcome.
Don't tell someone to read the manual. Chances are they have and don't get it.
Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.