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

  • Thread starter Thread starter ad
  • Start date Start date
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.
 
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.
 
Back
Top