string-comparison

How can I compare two strings to find the number of characters that match in R, using substitution distance?

感情迁移 提交于 2021-02-18 11:37:30
问题 In R, I have two character vectors, a and b. a <- c("abcdefg", "hijklmnop", "qrstuvwxyz") b <- c("abXdeXg", "hiXklXnoX", "Xrstuvwxyz") I want a function that counts the character mismatches between each element of a and the corresponding element of b. Using the example above, such a function should return c(2,3,1) . There is no need to align the strings. I need to compare each pair of strings character-by-character and count matches and/or mismatches in each pair. Does any such function exist

Compare two strings and Extract value of variable data in Python

风流意气都作罢 提交于 2021-02-11 06:16:41
问题 In my python script, I have a list of strings like, birth_year = ["my birth year is *","i born in *","i was born in *"] I want to compare one input sentence with the above list and need a birth year as output. The input sentence is like: Example1: My birth year is 1994. Example2: I born in 1995 The output will be: Example1: 1994 Example2: 1995 I applied many approaches by using regex. But I didn't find a perfect solution for the same. 回答1: If you change birth_year to a list of regexes you

Compare two strings and Extract value of variable data in Python

落爺英雄遲暮 提交于 2021-02-11 06:16:25
问题 In my python script, I have a list of strings like, birth_year = ["my birth year is *","i born in *","i was born in *"] I want to compare one input sentence with the above list and need a birth year as output. The input sentence is like: Example1: My birth year is 1994. Example2: I born in 1995 The output will be: Example1: 1994 Example2: 1995 I applied many approaches by using regex. But I didn't find a perfect solution for the same. 回答1: If you change birth_year to a list of regexes you

Comparing strings, containing space with == in PHP

与世无争的帅哥 提交于 2021-02-06 11:54:31
问题 I am curious why this is happening in PHP: '78' == ' 78' // true '78' == '78 ' // false I know that it's much better to use strcmp or the least === . I also know that when you compare numerical strings with == they are casted to numbers if possible. I also can accept that the leading space is ignored, so (int)' 78' is 78, and the answer is true in the first case, but I'm really confused why it's false in the second. I thought that '78' is casted to 78 and '78 ' is casted to 78 , too, so they

Comparing strings, containing space with == in PHP

丶灬走出姿态 提交于 2021-02-06 11:53:05
问题 I am curious why this is happening in PHP: '78' == ' 78' // true '78' == '78 ' // false I know that it's much better to use strcmp or the least === . I also know that when you compare numerical strings with == they are casted to numbers if possible. I also can accept that the leading space is ignored, so (int)' 78' is 78, and the answer is true in the first case, but I'm really confused why it's false in the second. I thought that '78' is casted to 78 and '78 ' is casted to 78 , too, so they

Why is `-lt` behaving differently for chars and strings?

懵懂的女人 提交于 2021-02-03 07:33:46
问题 I recently answered a SO-question about using -lt or -gt with strings. My answer was based on something I've read earlier which said that -lt compares one char from each string at a time until a ASCII-value is not equal to the other. At that point the result (lower/equal/greater) decides. By that logic, "Less" -lt "less" should return True because L has a lower ASCII-byte-value than l , but it doesn't: [System.Text.Encoding]::ASCII.GetBytes("Less".ToCharArray()) 76 101 115 115 [System.Text

What is the right string comparison value to be used in a machine to machine communication scenario?

我们两清 提交于 2021-01-28 05:33:03
问题 Consider a scenario where you are implementing code meant to be used for machine to machine communication. The typical example for that is the code executed inside a web API action method. Suppose that you want to perform an exact match between strings; maybe you have a list of users and you wan to find one specific user provided the user name: List<User> users = .... const string username = "user-123"; var user = users.Find(u => string.Equals(username, u.UserName)); In such a scneario should

Compare ISO 8601 date strings in javascript

痴心易碎 提交于 2021-01-21 07:03:20
问题 I want to compare ISO 8601 dates in javascript as strings instead of making Date objects for each string and comparing objects. var date_array = ['2012-10-01','2012-11-27','2012-12-23']; console.log(date_array[0] < date_array[1]) // gives true console.log(date_array[1] > date_array[2]) // gives false My reason for doing this is I believe string comparisons should be faster than making objects for each date string and comparing objects. These comparisons seem to work as expected in some

Compare ISO 8601 date strings in javascript

*爱你&永不变心* 提交于 2021-01-21 07:03:10
问题 I want to compare ISO 8601 dates in javascript as strings instead of making Date objects for each string and comparing objects. var date_array = ['2012-10-01','2012-11-27','2012-12-23']; console.log(date_array[0] < date_array[1]) // gives true console.log(date_array[1] > date_array[2]) // gives false My reason for doing this is I believe string comparisons should be faster than making objects for each date string and comparing objects. These comparisons seem to work as expected in some

How do I check if a string contains a certain character?

拥有回忆 提交于 2020-12-26 08:16:47
问题 I'm fairly new to C programming, how would I be able to check that a string contains a certain character for instance, if we had: void main(int argc, char* argv[]){ char checkThisLineForExclamation[20] = "Hi, I'm odd!" int exclamationCheck; } So with this, how would I set exclamationCheck with a 1 if "!" is present and 0 if it's not? Many thanks for any assistance given. 回答1: By using strchr(), like this for example: #include <stdio.h> #include <string.h> int main(void) { char str[] = "Hi, I