Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB InStr Equivalent in c#

Tags:

c#

vb.net

I am not sure why I get the result of 0, which is the correct value of a

I have in VB

Dim searched As String = "<results>" & vbCrLf & "<field name=\""FID\""/>" & vbCrLf & "<field name=\""StartFID\""/>" & vbCrLf & "<field name=\""Vertex1\""/>" & vbCrLf & "<field name=\""Vertex2\""/>" & vbCrLf & "<field name=\""Slope\""/>" & vbCrLf & ""

Dim sought As String = "<rs FID=\""87\"" StartFID=\""87\"" Vertex1=\""29\"" Vertex2=\""30\"" Slope=\""-1\""/>"

Dim a As Integer = InStr(searched, sought)

What I would like to do, is get the same result of a == 0 when converted to c#.

I have tried

int a = String.Compare(searched, sought);
int a = String.IndexOf(searched, sought);
int a = String.Equals(searched, sought);
like image 698
Deke Avatar asked Jul 04 '26 20:07

Deke


1 Answers

Strings in C# are zero-indexed. If a.IndexOf(b) returns 0, then string b is present in string a at position 0.

If the sought string is not in the input, IndexOf() returns -1.

like image 98
CodeCaster Avatar answered Jul 07 '26 09:07

CodeCaster



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!