c# version of InStr?

M

mp

looking in help for InStr it appears to give me pages using
Microsoft.VisualBasic.Strings namespace

yet other pages appear to suggest InStr is in C#
from local help
C# syntax
public static int InStr(
string String1,
string String2,
CompareMethod Compare
)

but when i use InStr in code
//get comments from original line

private string GetCommentFromLine(string line)

{if (instr(line,";")>0 )

{...}

}



I get
Error 1 The name 'instr' does not exist in the current context

even after adding
using Microsoft.VisualBasic;

same error

and again after adding a reference to Microsoft.VisualBasic in the
references

same error



stumped

mark
 
M

mp

Peter Duniho said:
mp said:
[...]
I get
Error 1 The name 'instr' does not exist in the current context

even after adding
using Microsoft.VisualBasic;

same error

and again after adding a reference to Microsoft.VisualBasic in the
references

same error

The fundamental problem is that you are forgetting that C# is
case-sensitive. You're trying to use a function named "instr", whereas
the function that exists in the VB library is named "InStr". Not the
same.

That said, you should try to avoid using the VB libraries.

I agree, which is why i went to the help files and put in c# instr as search
term.
that pulled up the ms vb library namespace which is why I posted here,
hoping there was a native c# object...which as you point out below is
..IndexOf....thanks


Nearly all
 

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