can anyone help how to do string comparision by ignoring case-sensitive ?
|
Re: How to do string comparision by ignoring case-sensitive ?
Well the easiest way is to convert both strings to lower or upper case: string s1 = "Hello" string s2 = "hEllo" print (lower s1 == lower s2) "\n"
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: How to do string comparision by ignoring case-sensitive ? Mathias Mamsch - Fri Nov 30 04:30:15 EST 2012
Well the easiest way is to convert both strings to lower or upper case: string s1 = "Hello" string s2 = "hEllo" print (lower s1 == lower s2) "\n"
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
This works nicely for plain ASCII characters (A-Z, a-z), but unfortunately not for non-latin (ΓΔΘФЦЩ etc) and accented characters (ÁÅÄÖÜÔ etc). const int CAPITAL_LETTER_A = 0x41 const int CAPITAL_LETTER_Z = 0x5a const int SMALL_LETTER_a = 0x61 const int SMALL_LETTER_z = 0x7a const int CAPITAL_LETTER_A_WITH_GRAVE_ACCENT = 0xc0 const int CAPITAL_ICELANDIC_LETTER_THORN = 0xde const int SMALL_LETTER_a_WITH_GRAVE_ACCENT = 0xe0 const int SMALL_ICELANDIC_LETTER_THORN = 0xfe const int MULTIPLICATION_SIGN = 0xd7 const int DIVISION_SIGN = 0xf7 const int CAPITAL_LETTER_S_WITH_CARON = 0x8a const int SMALL_LETTER_s_WITH_CARON = 0x9a const int CAPITAL_DIGRAPH_OE = 0x8c const int SMALL_DIGRAPH_oe = 0x9c const int CAPITAL_LETTER_Z_WITH_CARON = 0x8e const int SMALL_LETTER_z_WITH_CARON = 0x9e const int CAPITAL_LETTER_Y_WITH_DIAERESIS = 0x9f const int SMALL_LETTER_y_WITH_DIAERESIS = 0xff bool whiteSpace (char c) { return(c==' ' || c=='\t' || c=='\r' || c=='\n' || c=='\v' || c=='\f') } string toUpper (string s) { int i,n string sUpper = null if (currentANSIcodepage != 1252) return s // Unknown codepage... for (i = 0; i < length (s); i++) { n = intOf (s[i]) if ((n >= SMALL_LETTER_a && n <= SMALL_LETTER_z) || (n >= SMALL_LETTER_a_WITH_GRAVE_ACCENT && n <= SMALL_ICELANDIC_LETTER_THORN && n != DIVISION_SIGN)) n = n - 0x20 elseif (n == SMALL_LETTER_s_WITH_CARON) n = CAPITAL_LETTER_S_WITH_CARON elseif (n == SMALL_DIGRAPH_oe) n = CAPITAL_DIGRAPH_OE elseif (n==SMALL_LETTER_z_WITH_CARON) n = CAPITAL_LETTER_Z_WITH_CARON elseif (n == SMALL_LETTER_y_WITH_DIAERESIS) n = CAPITAL_LETTER_Y_WITH_DIAERESIS sUpper = sUpper charOf (n) "" } return sUpper } string toLower (string s) { int i,n string sLower = null if (currentANSIcodepage != 1252) return s // Unknown codepage... for (i = 0; i < length (s); i++) { n = intOf (s[i]) if (( n >= CAPITAL_LETTER_A && n <= CAPITAL_LETTER_Z) || (n >= CAPITAL_LETTER_A_WITH_GRAVE_ACCENT && n <= CAPITAL_ICELANDIC_LETTER_THORN && n != MULTIPLICATION_SIGN)) n = n + 0x20 elseif (n == CAPITAL_LETTER_S_WITH_CARON) n = SMALL_LETTER_s_WITH_CARON elseif (n == CAPITAL_DIGRAPH_OE) n = SMALL_DIGRAPH_oe elseif (n == CAPITAL_LETTER_Z_WITH_CARON) n = SMALL_LETTER_z_WITH_CARON elseif (n == CAPITAL_LETTER_Y_WITH_DIAERESIS) n = SMALL_LETTER_y_WITH_DIAERESIS sLower = sLower charOf(n) "" } return sLower } string toTitle (string s) { int i,n string sTitle = null bool upper = true if (currentANSIcodepage != 1252) return s // Unknown codepage... for (i = 0; i < length (s); i++) { n = intOf (s[i]) if (whiteSpace (s[i])) upper = true else { if (upper) { if ((n >= SMALL_LETTER_a && n <= SMALL_LETTER_z) || (n >= SMALL_LETTER_a_WITH_GRAVE_ACCENT && n <= SMALL_ICELANDIC_LETTER_THORN && n != DIVISION_SIGN)) n = n - 0x20 elseif (n == SMALL_LETTER_s_WITH_CARON) n = CAPITAL_LETTER_S_WITH_CARON elseif (n == SMALL_DIGRAPH_oe) n = CAPITAL_DIGRAPH_OE elseif (n == SMALL_LETTER_z_WITH_CARON) n=CAPITAL_LETTER_Z_WITH_CARON elseif (n == SMALL_LETTER_y_WITH_DIAERESIS) n = CAPITAL_LETTER_Y_WITH_DIAERESIS } elseif ((n >= CAPITAL_LETTER_A && n <= CAPITAL_LETTER_Z) || (n >= CAPITAL_LETTER_A_WITH_GRAVE_ACCENT && n <= CAPITAL_ICELANDIC_LETTER_THORN && n != MULTIPLICATION_SIGN)) n = n + 0x20 elseif (n == CAPITAL_LETTER_S_WITH_CARON) n = SMALL_LETTER_s_WITH_CARON elseif (n == CAPITAL_DIGRAPH_OE) n = SMALL_DIGRAPH_oe elseif (n == CAPITAL_LETTER_Z_WITH_CARON) n = SMALL_LETTER_z_WITH_CARON elseif (n == CAPITAL_LETTER_Y_WITH_DIAERESIS) n = SMALL_LETTER_y_WITH_DIAERESIS upper = false } sTitle = sTitle charOf (n) "" } return sTitle }
|
Re: How to do string comparision by ignoring case-sensitive ? |
Re: How to do string comparision by ignoring case-sensitive ? OurGuest - Mon Dec 03 11:34:05 EST 2012 |
Re: How to do string comparision by ignoring case-sensitive ? hell_se - Tue Dec 04 02:09:34 EST 2012 |
Re: How to do string comparision by ignoring case-sensitive ? OurGuest - Tue Dec 04 08:01:20 EST 2012
The unicode consortium says otherwise, which has put a clear distinction into capital, small and title case letters. See also: print u"abcdé".upper()
"ABCDÉ"
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: How to do string comparision by ignoring case-sensitive ? Mathias Mamsch - Tue Dec 04 09:40:48 EST 2012
The unicode consortium says otherwise, which has put a clear distinction into capital, small and title case letters. See also: print u"abcdé".upper()
"ABCDÉ"
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
If you want to make the comparison in DOORS your are a shoe out. |