Alex Rivera | Logout

String comparison: InvariantCultureIgnoreCase vs OrdinalIgnoreCase?

Asked 2010-05-01T11:00:08.033
248

Which would be better code:

int index = fileName.LastIndexOf(".", StringComparison.InvariantCultureIgnoreCase);

or

int index = fileName.LastIndexOf(".", StringComparison.OrdinalIgnoreCase);
Edit
Report

2 Answers

59

If you really want to match only the dot, then StringComparison.Ordinal would be fastest, as there is no case-difference.

"Ordinal" doesn't use culture and/or casing rules that are not applicable anyway on a symbol like a ..

answered 2010-05-01T11:38:50.970
19

You seem to be doing file name comparisons, so I would just add that OrdinalIgnoreCase is closest to what NTFS does (it's not exactly the same, but it's closer than InvariantCultureIgnoreCase)

answered 2010-05-01T11:23:43.497

Your Answer