string-comparison

How to compare the contents of two string objects in PowerShell

删除回忆录丶 提交于 2019-11-27 22:56: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? 回答1: You

How to compare strings ignoring the case

∥☆過路亽.° 提交于 2019-11-27 18:26:06
I want apple and Apple comparison to be true . Currently "Apple" == "Apple" # returns TRUE "Apple" == "APPLE" # returns FALSE molf 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. In Ruby 2.4.0 you have: casecmp?(other_str) → true, false, or nil "abcdef".casecmp?("abcde") #=> false "aBcDeF".casecmp?("abcdef") #=> true "abcdef".casecmp?("abcdefg") #=> false "abcdef".casecmp?("ABCDEF") #=> true

PostgreSQL: Case insensitive string comparison

≡放荡痞女 提交于 2019-11-27 18:20:16
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. First, what not to do, don't use ilike... create table y ( id serial not null, email text not null unique ); insert into y(email) values('iSteve.jobs@apple.com') ,('linus.Torvalds@linUX.com'); insert into y(email)

String.comparison performance (with trim)

北战南征 提交于 2019-11-27 18:02:29
问题 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

When to use which fuzz function to compare 2 strings

我的未来我决定 提交于 2019-11-27 17:32:10
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 use fuzzywuzzy to compare addresses. Rick Hanlon II Great question. I'm an engineer at SeatGeek, so I

String comparison in bash. [[: not found

这一生的挚爱 提交于 2019-11-27 17:21:44
I am trying to compare strings in bash. I already found an answer on how to do it on stackoverflow . In script I am trying, I am using the code submitted by Adam in the mentioned question: #!/bin/bash string='My string'; if [[ "$string" == *My* ]] then echo "It's there!"; fi needle='y s' if [[ "$string" == *"$needle"* ]]; then echo "haystack '$string' contains needle '$needle'" fi I also tried approach from ubuntuforums that you can find in 2nd post if [[ $var =~ regexp ]]; then #do something fi In both cases I receive error: [[: not found What am I doing wrong? [[ is a bash-builtin. Your /bin

What are some algorithms for comparing how similar two strings are?

最后都变了- 提交于 2019-11-27 17:03:21
I need to compare strings to decide whether they represent the same thing. This relates to case titles entered by humans where abbreviations and other small details may differ. For example, consider the following two titles: std::string first = "Henry C. Harper v. The Law Offices of Huey & Luey, LLP"; As opposed to: std::string second = "Harper v. The Law Offices of Huey & Luey, LLP"; A human can quickly gauge that these are most likely one and the same. The current approach I have taken is to normalize the strings by lowercasing all letters and removing all punctuation and spaces giving: std:

Compare versions as strings

家住魔仙堡 提交于 2019-11-27 16:42:00
问题 Comparing version numbers as strings is not so easy... "1.0.0.9" > "1.0.0.10", but it's not correct. The obvious way to do it properly is to parse these strings, convert to numbers and compare as numbers. Is there another way to do it more "elegantly"? For example, boost::string_algo... 回答1: I don't see what could be more elegant than just parsing -- but please make use of standard library facilities already in place. Assuming you don't need error checking: void Parse(int result[4], const std

How to properly compare command-line arguments?

浪子不回头ぞ 提交于 2019-11-27 16:10:35
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 main.c gender -s pilkington I enter that commands. Bu the output is always "OMG!!" Which part is wrong?

String comparison with logical operator in Java

你离开我真会死。 提交于 2019-11-27 15:46:07
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.println("No Hello"); } } } You shouldn't use == because it does something else then you think. In this case