string-comparison

Cast collation of nvarchar variables in t-sql

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 22:10:44
I need to change the collation of an nvarchar variable. By documentation : (...) 3. The COLLATE clause can be specified at several levels. These include the following: Casting the collation of an expression. You can use the COLLATE clause to apply a character expression to a certain collation. Character literals and variables are assigned the default collation of the current database. Column references are assigned the definition collation of the column. For the collation of an expression, see Collation Precedence (Transact-SQL). However I can't figure out the correct syntax for the usage of

bash [[ [a] == [a] ]] not true? square bracket affect compare result

丶灬走出姿态 提交于 2019-12-03 16:25:09
问题 Anyone know why this happens? Is this a bug of bash? x='mnt:[4026532411]' [[ $x == $x ]] && echo OK I am expecting result OK , but it did not. Of course, this works [[ "$x" == "$x" ]] && echo OK But as I know, bash [[ ]] have a merit that no need to quote var when compare. x='a b' [[ $x == $x ]] && echo OK works. Ironical things is x='mnt:[4026532411]' [[ $x != $x ]] && echo Oh my god result is Oh my god 回答1: The unquoted right-hand side of == and != is treated as a pattern, not a literal

How do I convert between a measure of similarity and a measure of difference (distance)?

北慕城南 提交于 2019-12-03 13:59:03
问题 Is there a general way to convert between a measure of similarity and a measure of distance? Consider a similarity measure like the number of 2-grams that two strings have in common. 2-grams('beta', 'delta') = 1 2-grams('apple', 'dappled') = 4 What if I need to feed this to an optimization algorithm that expects a measure of difference, like Levenshtein distance? This is just an example...I'm looking for a general solution, if one exists. Like how to go from Levenshtein distance to a measure

Optimized strcmp implementation

冷暖自知 提交于 2019-12-03 12:30:41
This function was found here . It's an implementation of strcmp : int strcmp(const char* s1, const char* s2) { while (*s1 && (*s1 == *s2)) s1++, s2++; return *(const unsigned char*)s1 - *(const unsigned char*)s2; } I understand all but the last line, in short what is going on in the last line? chux - Reinstate Monica return *(const unsigned char*)s1-*(const unsigned char*)s2; OP: in short what is going on in the last line? A: The first potential string difference is compared. Both chars are referenced as unsigned char as required by the spec. The 2 are promoted to int and the difference is

comparing two strings in SQL Server

为君一笑 提交于 2019-12-03 11:29:06
Is there any way to compare two strings in SQL Server 2008 stored procedure like below? int returnval = STRCMP(str1, str2) returns 0 if the strings are the same returns -1 if the first argument is smaller than the second according to the current sort order. returns 1 otherwise. Above method I find in the MySQL but not in SQL Server. There is no direct string compare function in SQL Server CASE WHEN str1 = str2 THEN 0 WHEN str1 < str2 THEN -1 WHEN str1 > str2 THEN 1 ELSE NULL --one of the strings is NULL so won't compare (added on edit) END Notes you can wraps this via a UDF using CREATE

Test if a string contains a word in PHP?

痞子三分冷 提交于 2019-12-03 10:45:51
问题 In SQL we have NOT LIKE %string% i need to do this in PHP. if ($string NOT LIKE %word%) { do something } i think that can be done with strpos() but couldnt figure out how.. i need exactly that comparission sentence in valid PHP. if ($string NOT LIKE %word%) { do something } Thanks 回答1: if (strpos($string, $word) === FALSE) { ... not found ... } Note that strpos() is case sensitive, if you want a case-insensitive search, use stripos() instead. Also note the === , forcing a strict equality test

Best way to compare the end of a string, use RIGHT, LIKE or other?

亡梦爱人 提交于 2019-12-03 07:16:42
I need to compare the end of strings against a list of possible ending in a stored procedure. It will be called a lot and there are around 10-15 candidate endings. At this point a code-only solution is preferable to creating tables dedicated to this. Something that would be like: IF (ENDSWITH(@var, 'foo') OR ENDSWITH(@var, 'bar') OR ENDSWITH(@var, 'badger') OR ENDSWITH(@var, 'snake')) ( ) I'm looking for the best way in terms of speed, but also maintainability. Candidates that I know of are RIGHT, my favorite so far but it means I have to hardcode the string length, so can be prone to error.

What are some good methods to find the “relatedness” of two bodies of text?

∥☆過路亽.° 提交于 2019-12-03 07:12:32
问题 Here's the problem -- I have a few thousand small text snippets, anywhere from a few words to a few sentences - the largest snippet is about 2k on disk. I want to be able to compare each to each, and calculate a relatedness factor so that I can show users related information. What are some good ways to do this? Are there known algorithms for doing this that are any good, are there any GPL'd solutions, etc? I don't need this to run in realtime, as I can precalculate everything. I'm more

bash [[ [a] == [a] ]] not true? square bracket affect compare result

谁都会走 提交于 2019-12-03 04:55:07
Anyone know why this happens? Is this a bug of bash? x='mnt:[4026532411]' [[ $x == $x ]] && echo OK I am expecting result OK , but it did not. Of course, this works [[ "$x" == "$x" ]] && echo OK But as I know, bash [[ ]] have a merit that no need to quote var when compare. x='a b' [[ $x == $x ]] && echo OK works. Ironical things is x='mnt:[4026532411]' [[ $x != $x ]] && echo Oh my god result is Oh my god The unquoted right-hand side of == and != is treated as a pattern, not a literal string. mnt:[4026532411] will match mnt: followed by exactly one of 0, 1, 2, 3, 4, 5, or 6, since the patterns

Is Nullable<int> a “Predefined value type” - Or how does Equals() and == work here?

时间秒杀一切 提交于 2019-12-03 04:24:51
For my own implementation of an Equals() method, I want to check a bunch of internal fields. I do it like this: ... _myNullableInt == obj._myNullableInt && _myString == obj._myString && ... I would assume, that this compares the values, including null, for equality not the object address (as a reference euqality compare operation would) because: It is said so for "predefined value types" in this MSDN doc here . I assume Nullable<int> is such a "predefined value type" because of it is in the System Namespace according to this MSDN doc . Am I right to assume that the VALUES are compared here?