Differences
This shows you the differences between two versions of the page.
python_wiki:string_normalization [2019/05/25 23:50] |
python_wiki:string_normalization [2019/05/25 23:50] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== String Normalization ====== | ||
+ | |||
+ | **General Information** | ||
+ | |||
+ | Normalizing strings prior to manipulations and comparisons. | ||
+ | |||
+ | **Checklist** | ||
+ | * Python 2 or 3 | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ====== Usage ====== | ||
+ | |||
+ | Using the code snippet. | ||
+ | <code bash> | ||
+ | chmod +x string-normalizing.py | ||
+ | ./ | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ====== The Code ====== | ||
+ | |||
+ | <code python string-normalizing.py> | ||
+ | # | ||
+ | |||
+ | # strings for testing | ||
+ | my_string1=" | ||
+ | my_string2=" | ||
+ | my_string3=" | ||
+ | my_string4=" | ||
+ | |||
+ | my_string_list = [my_string1, | ||
+ | |||
+ | ##-- Various Methods to Normalize Your Strings Prior to Comparison --## | ||
+ | for string in my_string_list: | ||
+ | # Original String | ||
+ | print(" | ||
+ | |||
+ | # Convert to all lowercase | ||
+ | print(" | ||
+ | |||
+ | # Convert to all uppercase | ||
+ | print(" | ||
+ | |||
+ | # Strip all white spaces from the left | ||
+ | print(" | ||
+ | |||
+ | # Strip all white paces from the right | ||
+ | print(" | ||
+ | |||
+ | # Strip both left and right spaces | ||
+ | print(" | ||
+ | </ | ||
+ | |||
+ | ---- | ||