Questions tagged [string-comparison]

string-comparison is the action of comparing strings, resulting in a boolean or an integer indicating the "distance" between the strings.

String comparison is the action of comparing strings.

The result of a string comparison may be a boolean or an integer; if it is an integer, then this measures the distance between the two strings, usually lexicographic distance. Note that this means that the strings are equal when the comparison yields 0.

There are some issues to be considered when comparing strings. First, there is the underlying type and encoding of the strings (Unicode? 8-byte chars? 16-byte chars?). Second, there is the question if case is relevant.

A classical mistake for beginning programmers is to compare strings using ==, or whatever other operator their programming language uses for comparing primitive types. In some languages, like Java and C, this will compare the instance of the strings (their reference or memory address, respectively), instead of the string itself.

Most programming languages provide built-in functions for comparing strings.

2237 questions
0
votes
0 answers

AttributeError: 'str' object has no attribute 'equals'

I keep getting this error and was wondering what was triggering it. This is my function definition: def spectMixGen(M, samp_size, source_pdf = "uniform", pdf_pars = 1, pure_pixels = 'no', max_purity = np.ones((1, p)), no_outliers = 0,…
A.Torres
  • 413
  • 1
  • 6
  • 16
0
votes
3 answers

Compare two hex numbers

I have a function that I use to compare two strings character by character and do some additional tasks on it. I want to modify it to compare hex numbers instead. For example: If A = "hello", B = "himan" were to be compared. I used to run a for loop…
davideej
  • 15
  • 6
0
votes
1 answer

Windows bat file how to verify output of a command

I want to verify an installation on a windows (XP) machine. So i want to create a .bat file that does the work. I want to verify commands like jruby --version and echo "OK" if it gives reasonable output. So in pseudocode: if( `jruby…
Jesper Rønn-Jensen
  • 106,591
  • 44
  • 118
  • 155
0
votes
0 answers

C# - Get StringComparer rules for all cultures

I don't need to compare strings, I need to retrieve rules, that StringComparer uses for each culture to use them somewhere else. Basically I need to get characters order for each culture. I understand that it's not really C# related, because I need…
user64675
  • 482
  • 7
  • 25
0
votes
1 answer

Compare two version numbers (true if different minor version)

I have to compare two version numbers (e. g. 5.6.2 and 5.7.0) in bash. But the function only has to return true if it is a higher or lower minor release number. Examples: | Old Version | New Version | return | | ----------- | ----------- | -------…
Jon
  • 188
  • 1
  • 9
0
votes
2 answers

Create a new column by comparing rows pandas

My dataframe looks like this df = pd.Dataframe({ 'a': ["10001", "10001", "10002", "10002" , "10002"], 'b': ['hello', 'hello', 'hola', 'hello', 'hola']}) I want to create a new column 'c' of boolean values with the following condition: If values of…
0
votes
1 answer

Compare the last digit of a string with that at the same place of another string

I need to compare 2 numeric strings in iOS. The first string, stored, is a fixed long number, and I want to check that the last digit of the second string entered is the same as the corresponding digit on the stored string (which isn't necessarily…
0
votes
1 answer

Compare two list containing varied string length and list length

I have two list ListA = ['John', 'Glucose', 'ABC', 'XYZ'....] ListB = ['XYZ', 'John', 'Mike',.....] num = [] for i in range(len(ListB)): for a in range(len(ListA)): if ListB[i] == ListA[a]: print(a) …
user9995331
  • 155
  • 5
0
votes
1 answer

How to compare Json data with array using Shell Script?

I have one json e.g var bbview ={ "tbl_am_api":[ { "Modified_User":"user1", "Modified_Time":"04-Jul-2018 01:40:05", "Line_Number":"SS001", "Service_Type":"BB3", "Status":"Yes", …
sandy
  • 121
  • 1
  • 3
  • 10
0
votes
1 answer

string Variable comparison in swift3

i have two variable string both have same time like a= 4:15 PM and b = 4:15 PM i am trying to compare these two variables in if to perform a specific task but it always returns false is there any solution?
Naqeeb
  • 1,121
  • 8
  • 25
0
votes
1 answer

I'm trying to iterate through two arrays in Java, while also checking to see if the values are equal

I am trying to iterate through many arrays, two at a time. They contain upwards of ten-thousand entries each, including the source. In which I am trying to assign each word to either a noun, verb, adjective, or adverb. I can't seem to figure a way…
0
votes
1 answer

python3 unicode string comparsion

I have a string that comes from a process' output, which seems to be unicode, and I can't compare it to a 'normal' string. Here is the code: proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) (out, err) = proc.communicate() result =…
katona.abel
  • 771
  • 4
  • 12
0
votes
2 answers

How Java Compiler treats the modified string at compile time

public class MyString { public static void main(java.lang.String[] args){ String a="Hello"; a=a.trim().concat("World"); String c="HelloWorld"; System.out.println(a==c);//returns false } interning should…
0
votes
1 answer

strcmp or array error?

i'm actually on a p2p chord node project and i have a problem when i try to create some command to collect information like temperature, light, id etc.. static void handle_cmd(volatile char* cmdLine) { int i = 0; volatile char* word[500] =…
Klyyde
  • 1
  • 3
0
votes
1 answer

PHP compare dates and highlight same

I would like to print days of month and highlight the days witch are same like dates in my MySQL table. There are rows of runs in table (day of run, distance, speed ...) and I would like to highlight days of month when I run. My…
Martin
  • 65
  • 1
  • 8
1 2 3
99
100