hi....
how to use the substring function.I have a string like (sr1234pr).ineed to get 1234 from this.'sr' and 'pr' is assigned in a variable.reply me plz...
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Hirendra SisodiyaPosted Mar 11, 2010, 5:08 AM
string str = "sr1234pr";
string tempstr = str.Substring(2, str.Length - 4);
or you need to find substring from another format let me know
thanks
Amit ChoudharyPosted Mar 11, 2010, 5:23 AM
Hirendra's code is right.. but if you want to utilize "sr" and "pr" string values in differet variables then
string str = "sr1234pr";
string tempstr = str.Substring(2, str.Length - 4);
string [] SplittedStrings=new SplittedStrings[10];
SplittedStrings=s.Split(new string[] { tempstr }, StringSplitOptions.RemoveEmptyEntries);
now you have the values splitted from str="sr1234pr" in an array. you can access them using an indexes.
Please mark as answer if it helps.