string-comparison

What is the difference between vbNullString, String.Empty and “”?

家住魔仙堡 提交于 2019-11-27 07:55:55
问题 All of these txtUsername.Text <> vbNullString txtUsername.Text <> String.Empty txtUsername.Text <> "" seem to return the same result. So, what's the difference between vbNullString , String.Empty and "" ? 回答1: vbNullString is a constant, more likely out of VB6, String.Empty and "" are the same, some say that there is a performance difference, but that is not true, it is your choice what you use. To check whether a string is empty you can use If String.IsNullOrEmpty(String) . The advantage is

Running NotePad++ from Command line with Compare Plugin showing compare result

心已入冬 提交于 2019-11-27 06:53:30
问题 I am trying to find a way to call notepad++ from command line with compare plugin showing the compare result providing I pass 2 files name which I want to compare. Think like I have a batch file, which does some work and result is opening notepad++ showing 2 files in compare mode. (Yes, compare plugin is installed) If anyone has any other suggestion to using any other editor or software also welcome.. 回答1: There's a tool called NppCompareLoader doing exactly what you want. Simply drop it in

Checking if 2 strings contain the same characters?

寵の児 提交于 2019-11-27 06:13:24
问题 Is there a way to check if two strings contain the same characters. For example, abc, bca -> true aaa, aaa -> true aab, bba -> false abc, def -> false 回答1: Turn each string into a char[], sort that array, then compare the two. private boolean sameChars(String firstStr, String secondStr) { char[] first = firstStr.toCharArray(); char[] second = secondStr.toCharArray(); Arrays.sort(first); Arrays.sort(second); return Arrays.equals(first, second); } 回答2: A very easy - but not very efficient - way

Behavior of unique index, varchar column and (blank) spaces

六眼飞鱼酱① 提交于 2019-11-27 06:03:27
问题 I'm using Microsoft SQL Server 2008 R2 (with latest service pack/patches) and the database collation is SQL_Latin1_General_CP1_CI_AS. The following code: SET ANSI_PADDING ON; GO CREATE TABLE Test ( Code VARCHAR(16) NULL ); CREATE UNIQUE INDEX UniqueIndex ON Test(Code); INSERT INTO Test VALUES ('sample'); INSERT INTO Test VALUES ('sample '); SELECT '>' + Code + '<' FROM Test WHERE Code = 'sample '; GO produces the following results: (1 row(s) affected) Msg 2601, Level 14, State 1, Line 8

String similarity with Python + Sqlite (Levenshtein distance / edit distance)

风流意气都作罢 提交于 2019-11-27 05:30:36
Is there a string similarity measure available in Python+Sqlite, for example with the sqlite3 module? Example of use case: import sqlite3 conn = sqlite3.connect(':memory:') c = conn.cursor() c.execute('CREATE TABLE mytable (id integer, description text)') c.execute('INSERT INTO mytable VALUES (1, "hello world, guys")') c.execute('INSERT INTO mytable VALUES (2, "hello there everybody")') This query should match the row with ID 1, but not the row with ID 2: c.execute('SELECT * FROM mytable WHERE dist(description, "He lo wrold gyus") < 6') How to do this in Sqlite+Python? Notes about what I've

Caselessly comparing strings in C#

混江龙づ霸主 提交于 2019-11-27 03:54:45
问题 Let's say I have two strings: a and b. To compare whether a and be have the same values when case is ignored, I've always used: // (Assume a and b have been verified not to be null) if (a.ToLower() == b.ToLower()) However, using Reflector, I've seen this a few times in the .NET Framework: // (arg three is ignoreCase) if (string.Compare(a, b, true) == 0) I tested which is faster, and the ToLower() beat Compare() every time with the strings I used. Is there a reason why to Compare() instead of

Why does string.Compare seem to handle accented characters inconsistently?

谁说胖子不能爱 提交于 2019-11-27 03:15:03
问题 If I execute the following statement: string.Compare("mun", "mün", true, CultureInfo.InvariantCulture) The result is '-1', indicating that 'mun' has a lower numeric value than 'mün'. However, if I execute this statement: string.Compare("Muntelier, Schweiz", "München, Deutschland", true, CultureInfo.InvariantCulture) I get '1', indicating that 'Muntelier, Schewiz' should go last. Is this a bug in the comparison? Or, more likely, is there a rule I should be taking into account when sorting

strcmp or string::compare?

心已入冬 提交于 2019-11-27 02:54:28
问题 I want to compare two strings. Is it possible with strcmp ? (I tried and it does not seem to work). Is string::compare a solution? Other than this, is there a way to compare a string to a char ? Thanks for the early comments. I was coding in C++ and yes it was std::string like some of you mentioned. I didn't post the code because I wanted to learn the general knowledge and it is a pretty long code, so it was irrelevant for the question. I think I learned the difference between C++ and C,

Compare two NSStrings

主宰稳场 提交于 2019-11-27 01:50:15
问题 In my app there is a mechanism that requires that at a certain point two NSString s will be the same to do something; for some reason when I compare the two, even when they are the same, it still doesn't recognize that. The code is something like this: NSString * aString = [self someMethodThatGetsAString]; NSString * bString; BOOL areStringsTheSame = NO; while (areStringsTheSame != YES) { bString = [self someMethodThatTakesNSStringsFromAnArrey]; if (bString == aString) { areStringsTheSame =

Complex “Contains” string comparison

安稳与你 提交于 2019-11-27 01:23:14
问题 I'm developing a C# 4.5 app and I need a function to return true for the following comparison: "bla LéOnAr d/o bla".ComplexContains("leonardo") In other words, I need string.Compare(str1, str2, CultureInfo.InvariantCulture, CompareOptions.IgnoreCase | CompareOptions.IgnoreSymbols | CompareOptions.IgnoreNonSpace) to also check for "contains! Can anyone help? 回答1: You could use an appropriate CompareInfo and then CompareInfo.IndexOf(string, string, CompareOptions) and check the result against