Q: search string in a string

G

Guest

Hello,
How would you search XYZ_ in a string and if exist, return next three
characters after string (so, if XYZ_001, return 001), otherwise return null
in C#.
Thanks,
Jim.
 
G

Guest

Where is this C# people? This works.

// search str1 in str2
private string SearchString(string str1,string str2)
{
string returnStr = "FAILED";

int pos = str2.IndexOf(str1);
if (pos >= 0)
{
returnStr = str2.Substring(pos + str1.Length, 3);
}
return returnStr;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top