471,319 Members | 2,663 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

Equivilent of VB InStr(Lcase())

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
Dec 13 '05 #1
4 6366
Why not combine them?

testString.ToLower().IndexOf("checkstring");

Dec 13 '05 #2
Thanks Chris,

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

I'll get the hang of this eventually!

Mike

"Chris Dunaway" wrote:
Why not combine them?

testString.ToLower().IndexOf("checkstring");

Dec 13 '05 #3
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/lib...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
"MikeLing" <Mi******@discussions.microsoft.com> wrote in message
news:40**********************************@microsof t.com...
| 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
Dec 13 '05 #4
> 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.

Dec 14 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by John Galt | last post: by
2 posts views Thread by Steve1 via DotNetMonster.com | last post: by
1 post views Thread by Ryan Ternier | last post: by
2 posts views Thread by Brian Henry | last post: by
2 posts views Thread by =?Utf-8?B?QW5kcmV3IEhheWVz?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.