Q: search string in a string

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
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

Back
Top