string-comparison

Date comparison in PHP

老子叫甜甜 提交于 2019-12-02 04:30:10
I currently have a date that's being stored in my SQL database as a VARCHAR of 255 characters. I declared this string as //within an object... $date = date(DATE_RFC822); Now, later on in the coding, I realise that I need to actually compare dates with each other. My initial, very naive attempt looked a little bit like this: if(object_1->date > object_2->date){ //do this that assumes that object_1 was created at a later date than object_2 }else{ continue; } While this worked fine for different times of the same day; using the code a week later began to show significant bugs. K4emic strtotime()

Java: How to use a switch statement [duplicate]

我的未来我决定 提交于 2019-12-02 03:39:36
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How do I compare strings in Java? I am having trouble understanding how to use a Java switch statement. After executing a method in one of the case statements, it still then goes to the default statement and runs that too. Here's the code: Scanner scanner = new Scanner(System.in); String option = null; while (option != "5") { ShowMenu(); option = scanner.nextLine(); switch (option) { case "1": ViewAllProducts();

Why is [ “$foo”==“$bar” ] always true in bash? [duplicate]

别来无恙 提交于 2019-12-02 02:46:27
This question already has an answer here: Why equal to operator does not work if it is not surrounded by space? 4 answers I tried to compare user input between to string Here is my code Encode="Encode" Decode="Decode" printf "Enter name of file: " read fileName printf "Encode Or Decode: " read EncOrDec if [ "$Encode"=="$EncOrDec" ]; then printf "Encode Nice\n" elif [ "$Decode"=="$EncOrDec" ]; then printf "Decode Nice\n" else printf "Nothing\n" fi Its always go to the Encode statement, Why?. And how to fix it In bash, spaces count. Replace: if [ "$Encode"=="$EncOrDec" ]; then With: if [ "

Compare strings with non-English characters?

时光总嘲笑我的痴心妄想 提交于 2019-12-02 01:25:16
I need to compare strings for a search mechanism on a web site. I use C#. I tried two ways: consultants.Where(x => x.Description.ToLower().Contains(vm.Description.ToLower())); and consultants.Where(x => Regex.IsMatch(x.Description, vm.Description, RegexOptions.IgnoreCase)); Both work fine for all English characters. So if I search for, say, "english", that's no problem. But as soon as I try searching for a string that contains non-English characters, it doesn't work. For example, if I try searching for the word "språk" ("language" in Swedish) it returns nothing. Why is that, and how can I

Java: How to use a switch statement [duplicate]

会有一股神秘感。 提交于 2019-12-02 01:12:52
Possible Duplicate: How do I compare strings in Java? I am having trouble understanding how to use a Java switch statement. After executing a method in one of the case statements, it still then goes to the default statement and runs that too. Here's the code: Scanner scanner = new Scanner(System.in); String option = null; while (option != "5") { ShowMenu(); option = scanner.nextLine(); switch (option) { case "1": ViewAllProducts(); break; case "2": ViewProductDetails(scanner); break; case "3": DeleteProduct(scanner); break; case "4": AddProduct(scanner); break; case "5": break; default: System

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

 ̄綄美尐妖づ 提交于 2019-12-02 00:26:48
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 result set with the probability higher than 95%. For example the current function is able to return 97.62% for jaro("Philadelphia","Philadelphlaa",9) I wish to tweak this function so that I am able to find "Philadelphia" for an input of "Philadelphlaa". What kind of

String StartsWith() issue with Danish text

拥有回忆 提交于 2019-12-01 23:49:25
Can anyone explain this behaviour? var culture = new CultureInfo("da-DK"); Thread.CurrentThread.CurrentCulture = culture; "daab".StartsWith("da"); //false I know that it can be fixed by specifying StringComparison.InvariantCulture . But I'm just confused by the behavior. I also know that "aA" and "AA" are not considered the same in a Danish case-insensitive comparision, see http://msdn.microsoft.com/en-us/library/xk2wykcz.aspx . Which explains this String.Compare("aA", "AA", new CultureInfo("da-DK"), CompareOptions.IgnoreCase) // -1 (not equal) Is this linked to the behavior of the first code

Sort months ( with strings ) algorithm

别来无恙 提交于 2019-12-01 16:19:13
问题 I have this months array: ["January", "March", "December" , "October" ] And I want to have it sorted like this: ["January", "March", "October", "December" ] I'm currently thinking in a "if/else" horrible cascade but I wonder if there is some other way to do this. The bad part is that I need to do this only with "string" ( that is, without using Date object or anything like that ) What would be a good approach? 回答1: If I had a way to supply a custom sorting order, I'd create a list defining

Why PHP casts two numerical strings to numbers before [loosely] comparing them?

匆匆过客 提交于 2019-12-01 15:19:21
I browsed through several similar questions, but they all only state the fact: If ... comparison involves numerical strings, then each string is converted to a number and the comparison performed numerically. Okay, I got it. It explains what is going on when '00001' == '1' returns TRUE . The question is: Why PHP does so? What is the reason for probing strings for being numeric, and then casting if so? Why can't we just compare two strings already? I can fairly understand what casting is required if two operands has different types. But why it does " usual math " when both are strings? You can

String comparison performance in C#

↘锁芯ラ 提交于 2019-12-01 13:47:23
问题 There are a number of ways to compare strings. Are there performance gains by doing one way over another? I've always opted to compare strings like so: string name = "Bob Wazowski"; if (name.CompareTo("Jill Yearsley") == 0) { // whatever... } But I find few people doing this, and if anything, I see more people just doing a straight == comparison, which to my knowledge is the worst way to compare strings. Am I wrong? Also, does it make a difference in how one compares strings within LINQ