string-comparison

Algorithm for almost similar values search

I have Persons table in SQL Server 2008. My goal is to find Persons who have almost similar addresses. The address is described with columns state, town, street, house, apartment, postcode and phone. Due to some specific differences in some states (not US) and human factor (mistakes in addresses etc.), address is not filled in the s...

locale aware string comparision

I´m using strcmp in combination with usort in order to sort an array of country names. Currently, the sort order is: Belgien Frankreich Italien Luxemburg Niederlande Spanien United Kingdom Österreich Which is correct, apart from the position of Österreich. It should be between Niederlande and Spanien. I also tried strnatcmp and strc...

rails comparing values of params[:id] and session[:user_id] not working

I'm new to rails after moving from PHP and am having no end to the frustrations, but hopefully there is a steep learning curve. I was following a guide on how to make a twitter clone in rails, and have continued along that path making it more and more twitter like. So I've got a 'users' page /users/show.html.erb which show all the pos...

How to fetch entries starting with the given string from a SQL Server database?

Hi I have a database with a lot of words to be used in a tag system. I have created the necessary code for an autocomplete box, but I am not sure of how to fetch the matching entries from the database in the most efficient way. I know of the LIKE command, but it seems to me that it is more of an EQUAL command. I get only the words that...

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

I was unable to find this on php.net. Is the double equal sign (==) case sensitive when used to compare strings in PHP? ...

Compare result from hexdigest() to a string

I've got a generated MD5-hash, which I would like to compare to another MD5-hash from a string. The statement below is false, even though they look the same when you print them and should be true. hashlib.md5("foo").hexdigest() == "acbd18db4cc2f85cedef654fccc4a4d8" Google told me that I should encode the result from hexdigest(), since...

How can I use jaro-winkler to find the closest value in a table?

I have an implementation of the jaro-winkler algorithm in my database. I did not write this function. The function compares two values and gives the probability of match. So jaro(string1, string2, matchnoofchars) will return a result. Instead of comparing two strings, I want to send one string with a matchnoofchars and then get a resu...

How to check whether a string is not null & empty?

I my web app, i have search fiedl where i get some string and a combo box. So, i am sending two arguments to the remote function. I want to check the user input is not null and not empty. So, then i can construct a valid query. public ArrayList findEmployees(String str, int dep)throws ClassNotFoundException, SQLException{ System.o...

Comparing Character Literal to Std::String in C++

I would like to compare a character literal with the first element of string, to check for comments in a file. Why use a char? I want to make this into a function, which accepts a character var for the comment. I don't want to allow a string because I want to limit it to a single character in length. With that in mind I assumed the e...

C#: Confusion about ToUpper() and ToLower()

if I do something like this... String myVar = "in"; if(myVar.ToUpper() == "in") { //do something } This is not going to go inside "if" block ..right? or Is it going to check BOTH for "in" AND "IN" and do whatever is there inside that if? If so, why is that ? Isn't it supposed to skip what's inside of "if" block? Same confusion...

Understanding NSString comparison in Objective-C

Both the following resolve to True: 1) @"foo" == @"foo" (is True) 2) NSString *myString1 = @"foo"; NSString *myString2 = @"foo"; myString1 == myString2 (is True) However, there are definitely times where two NSStrings cannot be compared using the equality operator, and [myString1 isEqualToString:myString2] is required instead. Ca...

'Regular Expression' VS 'String Comparison operators / functions'

Hello. This question is designed around the performance within PHP but you may broaden it to any language if you wish to. After many years of using PHP and having to compare strings I've learned that using string comparison operators over regular expressions is beneficial when it comes to performance. I fully understand that some oper...

How can I see if one string loosely contains another (case, extra whitespace, and punctuation ignored)?

I am writing a program in C# that compares strings similarly to the way that Google searches documents for keywords. I am wanting a search for "stack overflow" to return true for "stack overflow" (plain), "This is the stack overflow." (in the middle), "Welcome to Stack Overflow." (case insensitive), "I like stack overflow." (variable w...

How do I perform an encoding-independent string-comparison in Java?

I'm having a strange problem comparing strings. I send a string to my server (as bytes using getBytes()) from the client. I've ensured that encoding is the same on the client and server by starting both of them with -Dfile.encoding=UTF-8. I noticed the problem when I was trying to perform a valueOf on the string I receive from the clien...

String comparison and String interning in Java

When should one compare Strings as objects and when should one use their equals method? To make sure, I always use equals, but that doesn't seem very efficient. In what situations can I be certain that string1 == string2 is a safe to use? Thanks! ...

How to find a similar word for a misspelled one in PHP?

I'll explain my problem: I have a database table called country. It has two columns: ID and name. When I want to search for 'paris', but misspelled the word: 'pares' ('e' instead of 'i'), I won't get any result from DB. I want the the system to suggest similar words that could help in the search. So, I am looking for help writing a s...

Checking if 2 strings contain the same characters?

Is there a way to check if two strings contain the same characters. For example, abc, bca -> true aaa, aaa -> true aab, bba -> false abc, def -> false ...

Regex match that must contain all characters in a string

I'm sure this has already been asked and answered, but I honestly couldn't find my answer after searching for quite a bit and reading Regex Tutorial. What I'm looking to do is match a string that has the same characters and length as another string. For example, a string "abcde" would match "edcba" but would not match "abcdf" or "aabbc...

comparing static char [] and const char *

static char a[255] = "\0"; and const char *b = " "; now when I assign "abc" to a and b, for a the remainig 252 bytes stay '\0' and for b its not like that. So, when I try to compare them, they come out to be different. One solution is to just compare till sizeof(b) as we do in strncmp(). Is there any other way of doing it? Probably b...

why is compareTo returning true when it should be false?

I'm debugging erroneous search returns from my data structures class project. This current project required us to build an ordered unrolled linked list, and run a search on the contents, then return a sublist of items from an inclusive start point to an exclusive end point. In order to do this, I have to search the internal array to fi...