string-comparison

How to compare non english characters with accents

不羁岁月 提交于 2019-11-29 13:11:05
I want to compare 2 strings which have some non English character in them String1 = debarquer String2 = débárquér On comparing above 2 strings, they should say equal. Use the Collator class. It allows you to set a strength and locale and it will compare characters appropriately. It should be something similar to this (NOTE: I have not tested the program) import java.text.Collator; import java.util.Locale; public class CollatorExp { public static void main(String[] args) { Collator collator = Collator.getInstance(Locale.FRENCH); collator.setStrength(Collator.PRIMARY); if (collator.compare(

Is it safe to compare strings with 'greater than' and 'less than' in MySQL?

試著忘記壹切 提交于 2019-11-29 10:35:48
MySQL (5.1.41-3ubuntu12.10-log) seems to give predictable results on string comparison using > (greater than) and < (less than): select "a" > "a", "a" > "b", "b" > "a", "ab" > "aa", "ab" > "aabbbb"; +-----------+-----------+-----------+-------------+-----------------+ | "a" > "a" | "a" > "b" | "b" > "a" | "ab" > "aa" | "ab" > "aabbbb" | +-----------+-----------+-----------+-------------+-----------------+ | 0 | 0 | 1 | 1 | 1 | +-----------+-----------+-----------+-------------+-----------------+ and also seems to make use of keys: explain select productcode from products where productcode <

How to do advanced string comparison in Ruby?

一个人想着一个人 提交于 2019-11-29 10:23:02
问题 I am trying to compare 2 paragraphs of strings the output of which has to be the percentage of similarity. I have tried doing this using the diff method and some Natural Language Processing tools Is there a better way of doing this in ruby? 回答1: You may want to try the Levenshtein string distance algorithm for this. http://rubygems.org/gems/text has an implementation of this along with other helpful string comparison utils. 回答2: See my similar Question here what I needed but did not know what

How to compare the contents of two string objects in PowerShell

心不动则不痛 提交于 2019-11-29 09:03:01
In PowerShell I have an array of string objects, and I have an object that contains string objects. In Java you can do a .equals(aObject) to test if the string values match, whereas doing a == test if the two objects refer to the same location in memory. How do I run an equivalent .equals(aObject) in powershell? I'm doing this: $arrayOfStrings[0].Title -matches $myObject.item(0).Title These both have the exact same string values, but I get a return value of false. Any suggestions? manojlds You want to do $arrayOfString[0].Title -eq $myPbiject.item(0).Title -match is for regex matching ( the

comparing version numbers in c

半世苍凉 提交于 2019-11-29 07:11:29
I am seeing a lot of answers for this problem in other languages but I am trying to find out a way to compare 2 version numbers given as strings. For example str1 = "141.1.23" str2 = "141.1.22" I am trying to find a way to compare the integer values in the strings to see which one is larger. (In this case str1 would be larger). I thought about using sometime of combination with atoi and strtok but I know I wont be able to tokenize 2 strings at once. Any advice? I know I wont be able to tokenize 2 strings at once. Fortunately, you do not need to: make a function that takes a string, and parses

Why is “ss” equal to the German sharp-s character 'ß'?

妖精的绣舞 提交于 2019-11-29 04:46:37
问题 Coming from this question I'm wondering why ä and ae are different(which makes sense) but ß and ss are treated as equal. I haven't found an answer on SO even if this question seems to be related and even mentions "that ß will compare equal to SS in Germany, or similar" but not why. The only resource on MSDN I found was this: How to: Compare Strings Here is mentioned following but also lacks the why : // "They dance in the street." // Linguistically (in Windows), "ss" is equal to // the German

String.comparison performance (with trim)

一笑奈何 提交于 2019-11-29 04:01:38
I need to do alot of high-performance case-insensitive string comparisons and realized that my way of doing it .ToLower().Trim() was really stupid due do all the new strings being allocated So I digged around a little and this way seems preferable: String.Compare(txt1,txt2, StringComparison.OrdinalIgnoreCase) The only problem here is that I want to ignore leading or trailing spaces, ie Trim() but if I use Trim I have the same problem with string allocations. I guess I could check each string and see if it StartsWith(" ") or EndsWith(" ") and only then Trim. Either that or figure out the index

Is it better to compare strings using toLowerCase or toUpperCase in JavaScript?

柔情痞子 提交于 2019-11-28 23:20:37
I'm going through a code review and I'm curious if it's better to convert strings to upper or lower case in JavaScript when attempting to compare them while ignoring case. Trivial example: var firstString = "I might be A different CASE"; var secondString = "i might be a different case"; var areStringsEqual = firstString.toLowerCase() === secondString.toLowerCase(); or should I do this: var firstString = "I might be A different CASE"; var secondString = "i might be a different case"; var areStringsEqual = firstString.toUpperCase() === secondString.toUpperCase(); It seems like either "should" or

Could string comparisons really differ based on culture when the string is guaranteed not to change?

心已入冬 提交于 2019-11-28 18:32:14
I'm reading encrypted credentials/connection strings from a config file. Resharper tells me, "String.IndexOf(string) is culture-specific here" on this line: if (line.Contains("host=")) { _host = line.Substring(line.IndexOf( "host=") + "host=".Length, line.Length - "host=".Length); ...and so wants to change it to: if (line.Contains("host=")) { _host = line.Substring(line.IndexOf("host=", System.StringComparison.Ordinal) + "host=".Length, line.Length - "host=".Length); The value I'm reading will always be "host=" regardless of where the app may be deployed. Is it really sensible to add this

Is == in PHP a case-sensitive string comparison?

巧了我就是萌 提交于 2019-11-28 18:04:34
I was unable to find this on php.net. Is the double equal sign ( == ) case sensitive when used to compare strings in PHP? Colin Pickard Yes, == is case sensitive. You can use strcasecmp for case insensitive comparison Artefacto Yes, but it does a comparison byte-by-byte. If you're comparing unicode strings, you may wish to normalize them first. See the Normalizer class. Example (output in UTF-8): $s1 = mb_convert_encoding("\x00\xe9", "UTF-8", "UTF-16BE"); $s2 = mb_convert_encoding("\x00\x65\x03\x01", "UTF-8", "UTF-16BE"); //look the same: echo $s1, "\n"; echo $s2, "\n"; var_dump($s1 == $s2); /