![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Comparing strings - is it a bug? My computer has Hungarian regional setting, with the Hungarian default sort order. The official Hungarian alphabet is: a á b c d e é f g ... When I compare strings in PowerShell I receive this: [91] PS I:\>"á" -gt "a" True [92] PS I:\>"áb" -gt "ab" True [93] PS I:\>"ác" -gt "ab" True [94] PS I:\>"áb" -gt "ac" False I don't understand the last one! If "á" is greater than "a" (that's OK), then why "áb" is not greater than "ac"??????? Is it a bug? -- Tibor |
My System Specs![]() |
| | #2 (permalink) | ||||||||||||
| Guest | Re: Comparing strings - is it a bug? ASAIK, PowerShell converts the characters to their numeric values and then compares the two. Take into count that the comparison is not case-sensitive. Find the characters value, it may give you a hint: ([int[]][char[]]"áb" | measure-object -sum).sum ([int[]][char[]]"ac" | measure-object -sum).sum ----- Shay Levi $cript Fanatic http://scriptolog.blogspot.com
| ||||||||||||
My System Specs![]() | |||||||||||||
| | #3 (permalink) | ||||||||||||||||||||||||
| Guest | Re: Comparing strings - is it a bug? The result: [1] PS I:\>([int[]][char[]]"áb" | measure-object -sum).sum 323 [2] PS I:\>([int[]][char[]]"ac" | measure-object -sum).sum 196 Anyway, I don't think PS works the way you described... It's not that easy, because it should take into account the different sort orders of different cultures. Tibor
| ||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||
| | #4 (permalink) | ||||||||||||||||||||||||||||||||||||
| Guest | Re: Comparing strings - is it a bug? Hi The results from the below culture-aware script are both true on my machine, can you check yours? ############## $huCculture = "hu-HU" [scriptblock] $script = { $ab = ([int[]][char[]]"áb" | measure-object -sum).sum $ac = ([int[]][char[]]"ac" | measure-object -sum).sum $ab -gt $ac "áb" -gt "ac" } $oldCulture = [System.Threading.Thread]::CurrentThread.CurrentUICulture [System.Threading.Thread]::CurrentThread.CurrentUICulture = $huCculture [System.Threading.Thread]::CurrentThread.CurrentCulture = $huCculture & $script [System.Threading.Thread]::CurrentThread.CurrentUICulture = $oldCulture [System.Threading.Thread]::CurrentThread.CurrentCulture = $oldCulture ################# ----- Shay Levi $cript Fanatic http://scriptolog.blogspot.com
| ||||||||||||||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||||||||||||||
| | #5 (permalink) | ||||||||||||||||||||||||||||||||||||
| Guest | Re: Comparing strings - is it a bug? BTW, the numeric results I get: PS > ([int[]][char[]]"áb" | measure-object -sum).sum 1587 PS > ([int[]][char[]]"ac" | measure-object -sum).sum 196 ----- Shay Levi $cript Fanatic http://scriptolog.blogspot.com
| ||||||||||||||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||||||||||||||
| | #6 (permalink) | ||||||||||||||||||||||||||||||||||||
| Guest | Re: Comparing strings - is it a bug? My results for your script: True False -- Tibor "Shay Levi" wrote:
| ||||||||||||||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||||||||||||||
| | #7 (permalink) | ||||||||||||||||||||||||||||||||||||
| Guest | Re: Comparing strings - is it a bug? What are the values you get for $ab and $ac? ----- Shay Levi $cript Fanatic http://scriptolog.blogspot.com
| ||||||||||||||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||||||||||||||
| | #8 (permalink) |
| Guest | Re: Comparing strings - is it a bug? When both operands are strings PowerShell compares strings as strings, alphabetically: # true because á's position in the alphabet is greater than a's 'á'-gt'a' # true, same as before; the next element in both operands is the same 'áb'-gt'ab' # true, á's position in the alphabet is greater than a's # and so is c's position regarding b's 'ác'-gt'ab' # false, even though á's position is greater than a's # b's position is lower than c's; the string 'áb' comes # before -or is less than- 'ac' when sorted alphabetically 'áb'-gt'ac' # sorting the strings demonstrates it 'á','a' | sort 'áb','ab' | sort 'ác','ab'| sort 'áb','ac'| sort # compare numbers as strings # true, obviously '13'-gt'12' # sort numbers as strings '13','12'|sort # false, but 123 is greater than 13 # the thing is that they are strings not integers '123'-gt'13' # sort numbers as strings '123','13'|sort -- Kiron |
My System Specs![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Comparing two lists | KeithK | PowerShell | 4 | 07-09-2008 05:27 PM |
| comparing hashtable values | Cookiecutter | PowerShell | 4 | 05-20-2008 10:36 AM |
| comparing secure strings... | Ben Christian | PowerShell | 3 | 04-02-2008 03:42 PM |
| comparing dates to $null | Hal Rottenberg | PowerShell | 5 | 08-27-2007 11:49 AM |
| Comparing filenames to strings | Tim | PowerShell | 17 | 08-24-2007 10:34 AM |