Contains and StringComparison.InvariantCultureIgnoreCase

  • Thread starter Thread starter Shapper
  • Start date Start date
S

Shapper

Hello,

I have the following:

String.Equals(a.Author, "CamÕes",
StringComparison.InvariantCultureIgnoreCase);

However a.Author has more than one word. So what I was really looking
for is something like:

a.Author.Contains("CamÕes",
StringComparison.InvariantCultureIgnoreCase);

How can I do this?

Thank you,

Miguel
 
There are lots of discussions over the past few years on the topic,
which Google Groups could have turned up for you.  But the short answer
is to use the string.IndexOf() method.

It's not the only way, and depending on the exact scenario might not
even be the completely best, optimal way.  But it seems pretty
straightforward and readable to me.

Pete

Yes, I am trying the following:

String text = "O livro de Camões";

Boolean a = text.IndexOf("livro",
StringComparison.InvariantCultureIgnoreCase) != -1;

Boolean b = text.IndexOf("LIVRO",
StringComparison.InvariantCultureIgnoreCase) != -1;

Boolean c = text.IndexOf("Camões",
StringComparison.InvariantCultureIgnoreCase) != -1;

Boolean d = text.IndexOf("CAMÕES",
StringComparison.InvariantCultureIgnoreCase) != -1;

Boolean e = text.IndexOf("Camoes",
StringComparison.InvariantCultureIgnoreCase) != -1;

Boolean f = text.IndexOf("Camões",
StringComparison.InvariantCultureIgnoreCase) != -1;

The only that fails is Camoes ... But I would like to have it pass.
Any idea why is not working?

Thank You,
Miguel
 
Back
Top