string-comparison

PostgreSQL: Case insensitive string comparison

放肆的年华 提交于 2019-11-26 19:26:41
问题 Is there a simple ignore-case-comparison for PostgreSQL? I want to replace: SELECT id, user_name FROM users WHERE lower(email) IN (lower('adamB@a.com'), lower('eveA@b.com')); With something like: SELECT id, user_name FROM users WHERE email IGNORE_CASE_IN ('adamB@a.com', 'eveA@b.com'); The like and ilike operators work on single values (e.g. like 'adamB@a.com' ), but not on sets. 回答1: First, what not to do, don't use ilike... create table y ( id serial not null, email text not null unique );

How to compare strings ignoring the case

折月煮酒 提交于 2019-11-26 19:26:07
问题 I want apple and Apple comparison to be true . Currently "Apple" == "Apple" # returns TRUE "Apple" == "APPLE" # returns FALSE 回答1: You're looking for casecmp. It returns 0 if two strings are equal, case-insensitively. str1.casecmp(str2) == 0 "Apple".casecmp("APPLE") == 0 #=> true Alternatively, you can convert both strings to lower case (str.downcase) and compare for equality. 回答2: In Ruby 2.4.0 you have: casecmp?(other_str) → true, false, or nil "abcdef".casecmp?("abcde") #=> false "aBcDeF"

When to use which fuzz function to compare 2 strings

痞子三分冷 提交于 2019-11-26 18:59:31
问题 I am learning fuzzywuzzy in Python. I understand the concept of fuzz.ratio , fuzz.partial_ratio , fuzz.token_sort_ratio and fuzz.token_set_ratio . My question is when to use which function? Do I check the 2 strings' length first, say if not similar, then rule out fuzz.partial_ratio ? If the 2 strings' length are similar, I'll use fuzz.token_sort_ratio ? Should I always use fuzz.token_set_ratio ? Anyone knows what criteria SeatGeek uses? I am trying to build a real estate website, thinking to

How do I compare two strings in Perl?

余生长醉 提交于 2019-11-26 18:42:25
How do I compare two strings in Perl? I am learning Perl, I had this basic question looked it up here on StackOverflow and found no good answer so I thought I would ask. See perldoc perlop . Use lt , gt , eq , ne , and cmp as appropriate for string comparisons: Binary eq returns true if the left argument is stringwise equal to the right argument. Binary ne returns true if the left argument is stringwise not equal to the right argument. Binary cmp returns -1, 0, or 1 depending on whether the left argument is stringwise less than, equal to, or greater than the right argument. Binary ~~ does a

Comparing strings with tolerance

痞子三分冷 提交于 2019-11-26 18:27:03
I'm looking for a way to compare a string with an array of strings. Doing an exact search is quite easy of course, but I want my program to tolerate spelling mistakes, missing parts of the string and so on. Is there some kind of framework which can perform such a search? I'm having something in mind that the search algorithm will return a few results order by the percentage of match or something like this. You could use the Levenshtein Distance algorithm . "The Levenshtein distance between two strings is defined as the minimum number of edits needed to transform one string into the other, with

Why does the default string comparer fail to maintain transitive consistency?

橙三吉。 提交于 2019-11-26 18:06:15
问题 I know this issue has been noted before, more or less concisely, but I still create this new thread because I ran into the issue again when writing a unit test. The default string comparison (that is the culture-dependent case-sensitive comparison that we get with string.CompareTo(string) , Comparer<string>.Default , StringComparer.CurrentCulture , string.Compare(string, string) and others) violates transitivity when the strings contain hyphens (or minus signs, I am talking about plain U+002D

How do I compare two strings in python?

守給你的承諾、 提交于 2019-11-26 17:59:31
问题 I have two strings like string1="abc def ghi" and string2="def ghi abc" How to get that this two string are same without breaking the words? 回答1: Seems question is not about strings equality, but of sets equality. You can compare them this way only by splitting strings and converting them to sets: s1 = 'abc def ghi' s2 = 'def ghi abc' set1 = set(s1.split(' ')) set2 = set(s2.split(' ')) print set1 == set2 Result will be True 回答2: If you want to know if both the strings are equal, you can

String comparison with logical operator in Java

妖精的绣舞 提交于 2019-11-26 17:20:45
问题 When comparing two strings, I was taught that we shouldn't use the logical operator (==). We should use String.equals(String) for the comparison. However, I see that the following code complies and prints " Hello Friend " with the latest JDK(1.6_23). I tried searching around and couldn't find any reference. From when is this happening? public class StringComp{ public static void main(String args[]){ String s = "hello"; if(s=="hello"){ System.out.println("Hello Friend"); }else{ System.out

How to properly compare command-line arguments?

纵饮孤独 提交于 2019-11-26 17:15:50
问题 I am trying to write a C code which takes arguments in main; thus when I write some strings in cmd, the program doing somethings inside it. But I am doing something wrong and I can't find it. This is the code: #include <stdio.h> #include <stdlib.h> int main(int argc, char * argv[]){ //File name is main.c if(argc != 3) printf("Wrong!!!!!!!!!"); else if (argv[1] == "-s") girls(); //Prints "Girls" else if(argv[1] == "-k") boys(); //Prints "Boys" else printf("OMG!!"); } In the cmd; gcc -o gender

Check if string is a punctuation character

北慕城南 提交于 2019-11-26 17:14:44
问题 Let's say I have a String array that contains some letters and punctuation String letter[] = {"a","b","c",".","a"}; In letter[3] we have "." How can I check if a string is a punctuation character? We know that there are many possible punctuation characters (,.?! etc.) My progress so far: for (int a = 0; a < letter.length; a++) { if (letter[a].equals(".")) { //===>> i'm confused in this line System.out.println ("it's punctuation"); } else { System.out.println ("just letter"); } } 回答1: Do you