string-comparison

Force localeCompare to be case-sensitive

不羁的心 提交于 2020-01-01 08:20:26
问题 I'm trying to use JavaScript's localeCompare function for sorting strings. I was surprised by the results of running the following lines in the devTools console: "a".localeCompare("b") // returns: -1 "A".localeCompare("b") // returns: -1 Another test: "b".localeCompare("a") // returns: 1 "B".localeCompare("a") // returns: 1 Even when I am more specific about my sort I get the same result: "a".localeCompare("b", { usage: "sort", sensitivity: 'variant' }) // -1 "A".localeCompare("b", { usage:

What's the best way to compare two strings for equality in C? [duplicate]

时间秒杀一切 提交于 2019-12-31 04:55:08
问题 This question already has answers here : C Strings Comparison with Equal Sign (5 answers) Closed 5 years ago . I have got two strings (string literals in that case), say char *name = "Fotis"; char *second_name = "Fotis"; and I have two ways to compare them, which are both giving me an accurate result. The first one is with the equality operator ( == ), likewise: if (name == second_name) printf ("Great success!\n"); and the second one is through the strcmp function available in string.h : if

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

爷,独闯天下 提交于 2019-12-31 04:07:25
问题 This question already has answers here : Why equal to operator does not work if it is not surrounded by space? (4 answers) Closed last year . 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

How Java String pool works when String concatenation?

旧城冷巷雨未停 提交于 2019-12-30 05:24:07
问题 Beware: I'm not trying to compare if the characters are equals. Because I know how to use the String.equals() method. This question is about String reference I was studying for the OCA exam when I started to learn about the class String and it properties as immutability, etc. According to what I read or may understand about String pool is that when a string is created Java stores this object on what they call String pool and if a new string is created with the same value it is going to make

How to compare version numbers in C++ [duplicate]

☆樱花仙子☆ 提交于 2019-12-29 08:52:08
问题 This question already has answers here : Compare versions as strings (4 answers) Closed 3 years ago . Our professor want us to write a program to compare two version numbers, like 0.1 < 0.2 or 1 < 1.1. Also there are some trick ones like .0.4 < .1. So, my idea is first judge if the number start as a dot, if it does, I add a 0 to it. After that I remove other dots except the first one. Then I convert string to number and compare them. Here's what I do in the first step. string numb1,numb2; if

Compare the text of two text fields

十年热恋 提交于 2019-12-29 01:43:07
问题 How do you compare the text in two text fields to see if they are the same, such as in "Password" and "Confirm Password" text fields? if (passwordField == passwordConfirmField) { //they are equal to each other } else { //they are not equal to each other } 回答1: In Objective-C you should use isEqualToString:, like so: if ([passwordField.text isEqualToString:passwordConfirmField.text]) { //they are equal to each other } else { //they are *not* equal to each other } NSString is a pointer type.

Python: Why does (“hello” is “hello”) evaluate as True? [duplicate]

拈花ヽ惹草 提交于 2019-12-27 17:29:37
问题 This question already has answers here : About the changing id of an immutable string (5 answers) Closed last year . Why does "hello" is "hello" produce True in Python? I read the following here: If two string literals are equal, they have been put to same memory location. A string is an immutable entity. No harm can be done. So there is one and only one place in memory for every Python string? Sounds pretty strange. What's going on here? 回答1: Python (like Java, C, C++, .NET) uses string

adding a new user to list in c program

随声附和 提交于 2019-12-24 22:03:34
问题 Im just trying to write a simple function to addd a friend to a UserAccount list. All the information is provided through the parameter. If the user is already in the list I do not need add him again but display records saying he is already in list. I wrote this piece of code. not sure if this is correct, any suggestion to improve the code? Does this work? int add_friend(UserAccount* user, char Circle, UserAccount* friend) { struct UserAccountNode *p; p = (struct UserAccountNode *) malloc

C# string comparision 'ö' 'oe' 'o' [duplicate]

ε祈祈猫儿з 提交于 2019-12-24 03:05:41
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: how to recognize similar words with difference in spelling I am trying to get returned true while comparing these 3 strings: 'voest', 'vost' and 'vöst' (German culture), because it is the same word. (In fact, only oe and ö are the same, but e.g. for a DB collation CI it is the same which is correct, because 'vost' is a misstyped 'voest') string.Compare(..) / string.Equals(..) returns always false no matter what

Difference between the different overloads of String.Compare

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-23 09:26:45
问题 Concretely what is the difference between String.Compare(String, String, StringComparison) and String.Compare(String, String, CultureInfo, CompareOptions) I feel like that the second one offers more options (comparison using any culture instead of only the current one or invariant one, ignore special characters, ignore the width of katakanas (!!) etc...) than the first one. Both have been introduced it in .NET 2.0 so I guess it can't be a question of backward compatibility. So what's the