string-comparison

Make Entity Framework be case-insensitive

*爱你&永不变心* 提交于 2019-12-05 09:51:55
Is it possible to set entity framework string comparison case insensitive by default? If I use string.StartsWith("stringToCompare", StringComparison.CurrentCultureIgnoreCase) it works. But when I need to use string.Contains("strigToCompare") it doesn't have an overload. You can simply change the case of both fields to Upper Case: String stringToCompare = "Some String"; string.ToUpper().Contains(stringToCompare.ToUpper()) This will make the search case-insensitive by converting all case to upper. Of course, ToLower() would work as well. 来源: https://stackoverflow.com/questions/3069241/make

Cast collation of nvarchar variables in t-sql

与世无争的帅哥 提交于 2019-12-05 08:50:29
问题 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

Comparing strings with the format “2.0.1”, “2.0.09”

◇◆丶佛笑我妖孽 提交于 2019-12-05 07:34:42
I need to get the user's app version number and compare it with the current app version on my server. If the user's app version is lower, then he will get a pop-up to update his app. While doing this, I need to compare the version of the app with the versions that are available. How can I compare the strings which are in the format "2.0.1" and "2.0.09" and get the highest one, in Objective-C? csano How about using the compare:options: method of the NSString class? NSString *v1 = @"2.0.1"; NSString *v2 = @"2.1"; NSComparisonResult result = [v1 compare:v2 options:NSNumericSearch]; if (result ==

Best way to compare 2 urls [closed]

Deadly 提交于 2019-12-05 02:46:55
I want to compare 2 URLs. Whats the best way to do this? Conditions: 1) It should exclude the http scheme. 2) 'foo.com/a/b' and 'foo.com/a' should be a match. You should use the Uri.Compare method. Here is an example to compare two URI's with different schemes. public static void Test() { Uri uri1 = new Uri("http://www.foo.com/baz?bar=1"); Uri uri2 = new Uri("https://www.foo.com/BAZ?bar=1"); var result = Uri.Compare(uri1, uri2, UriComponents.Host | UriComponents.PathAndQuery, UriFormat.SafeUnescaped, StringComparison.OrdinalIgnoreCase); Debug.Assert(result == 0); } use the c# URI class to

Sorting names with numbers correctly

萝らか妹 提交于 2019-12-05 02:41:03
问题 For sorting item names, I want to support numbers correctly. i.e. this: 1 Hamlet 2 Ophelia ... 10 Laertes instead of 1 Hamlet 10 Laertes 2 Ophelia ... Does anyone know of a comparison functor that already supports that? (i.e. a predicate that can be passed to std::sort ) I basically have two patterns to support: Leading number (as above), and number at end, similar to explorer: Dolly Dolly (2) Dolly (3) (I guess I could work that out: compare by character, and treat numeric values differently

How to index a postgres table by name, when the name can be in any language?

冷暖自知 提交于 2019-12-05 00:32:05
问题 I have a large postgres table of locations (shops, landmarks, etc.) which the user can search in various ways. When the user wants to do a search for the name of a place, the system currently does (assuming the search is on cafe): lower(location_name) LIKE '%cafe%' as part of the query. This is hugely inefficient. Prohibitively so. It is essential I make this faster. I've tried indexing the table on gin(to_tsvector('simple', location_name)) and searching with (to_tsvector('simple',location

Why should I use string.length == 0 over string == “” when checking for empty string in ECMAScript?

不问归期 提交于 2019-12-05 00:15:54
Most of the developers on my current project use a (to me) strange way to check for empty strings in ECMAScript: if (theString.length == 0) // string is empty I would normally write this instead: if (theString == "") // string is empty The latter version seems more readable and natural to me. Nobody I asked seemed to be able to explain the advantages of version 1. I guess that at some time in the past somebody told everybody that this is the way to do it, but now that person left and nobody remembers why it should be done this way. I'm wondering whether there is a reason why I should choose

How to fetch entries starting with the given string from a SQL Server database?

↘锁芯ラ 提交于 2019-12-04 23:36:04
I have a database with a lot of words to be used in a tag system. I have created the necessary code for an autocomplete box, but I am not sure of how to fetch the matching entries from the database in the most efficient way. I know of the LIKE command, but it seems to me that it is more of an EQUAL command. I get only the words that looks exactly like the word I enter. My plan is to read every row, and then use C#'s string.StartsWith() and string.Contains() functions to find words that may fit, but I am thinking that with a large database, it may be inefficient to read every row and then

In R - fastest way pairwise comparing character strings on similarity

丶灬走出姿态 提交于 2019-12-04 21:59:33
I'm looking for a way to speed up the following approach. Any pointers are very welcome. Where are the bottlenecks? Say I have the following data.frame : df <- data.frame(names=c("A ADAM", "S BEAN", "A APPLE", "J BOND", "J BOND"), v1=c("Test_a", "Test_b", "Test_a", "Test_b", "Test_b"), v2=c("Test_c", "Test_c", "Test_d", "Test_d", "Test_d")) I want to compare each pair of rows in df on their JaroWinkler similarity. With some help of others ( see this post ), I've been able to construct this code: #columns to compare testCols <- c("names", "v1", "v2") #compare pairs RowCompare= function(x){ comp

Comparing different strings in PHP with == returns true

寵の児 提交于 2019-12-04 14:15:14
I was just debugging a script and found that an if-statement wasn't working the way I expected it to. var_dump("6064365413078728979" == "6064365413078728452"); die(); The code above will result in the following: bool(true) With the === operator it works as expected. Anyone got any ideas why? I'm using PHP Version 5.3.13 with a wamp installation on a x64 windows machine. Hanky Panky <?php $a=6064365413078728979; $b=6064365413078728452; echo $a."<br>".$b; //var_dump( $a==$b ); die(); ?> When you run that, then on your machine that might be exceeding limit for a number and that is a numeric