Equivilent of VB InStr(Lcase())

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

String.IndexOf is case sensitive so I need to covert to lower before testing
the string contains a given string. In VB this is:

Instr(Lcase(StringToTest, "StringToCheckFor"))

What is the C# equivilent? The closest I've comeup with is:

string lowerString = testString.ToLower();
lowerString.IndexOf("checkstring")

Thanks,

Mike
 
Thanks Chris,

I tried to do that but had forgotten to add the () after ToLower.

I'll get the hang of this eventually!

Mike
 
Mike,
In addition to the other comments.

If you have .NET 2.0 (VS 2005), you can use the overloaded String.IndexOf
that accepts a StringComparison parameter:

http://msdn2.microsoft.com/en-us/library/ms224425(en-US,VS.80).aspx

Either StringComparison.CurrentCultureIgnoreCase or
StringComparison.InvaiantCultureIgnoreCase should give you what you are
after...

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| Hi,
|
| String.IndexOf is case sensitive so I need to covert to lower before
testing
| the string contains a given string. In VB this is:
|
| Instr(Lcase(StringToTest, "StringToCheckFor"))
|
| What is the C# equivilent? The closest I've comeup with is:
|
| string lowerString = testString.ToLower();
| lowerString.IndexOf("checkstring")
|
| Thanks,
|
| Mike
 
I tried to do that but had forgotten to add the () after ToLower.

That gets me all the time coming from VB.Net where it is not required.
I wish the IDE were smart enough to insert them for me when I hit the
period key.
 

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