What is the C# equivelant of the function InStr in VB?

A

ad

There are InStr in VB
What is the C# equivelant of the function InStr in VB?


----------------------------------------------------------------------------
------------------
SearchString ="XXpXXpXXPXXP" ' String to search in.
SearchChar = "P" ' Search for "P".

' Comparison is binary by default (last argument is omitted).
MyPos = InStr(SearchString, SearchChar) ' Returns 9.
 
A

Antonio Pelleriti

ad ha scritto:
There are InStr in VB
What is the C# equivelant of the function InStr in VB?


----------------------------------------------------------------------------
------------------
SearchString ="XXpXXpXXPXXP" ' String to search in.
SearchChar = "P" ' Search for "P".

' Comparison is binary by default (last argument is omitted).
MyPos = InStr(SearchString, SearchChar) ' Returns 9.

SearchString ="XXpXXpXXPXXP";
int myPos=SearchString.IndexOf("P");

returns 8, the index is zero-based.
 

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

Top