
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Controlling Case Sensitivity When Comparing Two Strings
|
49
There are several drawbacks to this approach. First, if the string of tokens is not sep-
arated by any well-defined character(s), it will be impossible to use the
Split method
to break up the string. For example, if the
equation string looked like this:
string equation = "1+2-4*5";
you would clearly have to use a more robust method of tokenizing this string (see
Recipe 10.7 for a more robust tokenizer).
A second drawback is that a string of tokenized words must be entered consistently
in order to gain meaning from the tokens. For example, if you ask users to type in
their names, they may enter any of the following:
John Doe
Doe John
John Q Doe
If one user enters his name the first way and another user enters it the second way,
your code will have a difficult time determining whether the first token in the string
array represents the first or last name. The same problem will exist for all of the other
tokens in the array. However, if all users enter their names in a consistent style, such
as
First Name, space, Last Name, you will have a much easier time tokenizing the name
and understanding what each token represents.
See Also
See Recipe 10.7; see the “String.Split Method” topic in the MSDN documentation.
2.7 Controlling Case Sensitivity ...