string-comparison

How do I determine if the value of a string variable changed in C#?

▼魔方 西西 提交于 2019-12-10 18:27:18
问题 I have something to do under a button click (add values to listbox) only if a particular string changes from its previous value. How do I manage this? Below is a sample of my code: private void button6_Click(object sender, EventArgs e) { string x = //some varying value I get from other parts of my program listBox1.Items.Clear(); listBox1.Items.Add(x + /*other things*/); } I can at times have same value for string x from previous value when clicking button6. In such cases I don't want listBox1

Java: Most efficient way to check if a String is in a wordlist

限于喜欢 提交于 2019-12-10 16:44:32
问题 I have an array of strings String[] words and a 28000 word Word-list. I want to check if any member of the String array is in the WordList (the word-list is in a text file wordlist.txt) What is the most efficient way to go about this? 回答1: Place the strings directly into a HashSet<String> rather than an array and iterate through the file using contains on the set to check the content. You wont improve on O(1) access. This will also mimimize memory used to store the Strings should any

Unicode characters causing issues in SQL Server 2005 string comparison

好久不见. 提交于 2019-12-10 15:39:06
问题 This query: select * from op.tag where tag = 'fussball' Returns a result which has a tag column value of "fußball". Column "tag" is defined as nvarchar(150). While I understand they are similar words grammatically, can anyone explain and defend this behavior? I assume it is related to the same collation settings which allow you to change case sensitivity on a column/table, but who would want this behavior? A unique constraint on the column also causes failure on inserts of one value when the

Character after hyphen affects string.compare

核能气质少年 提交于 2019-12-10 14:58:35
问题 I would expect "2-" and "22" to always compare the same way, but changing the 3rd character changes the sort order. string.Compare("2-1","22-", StringComparison.CurrentCulture) //-1 string.Compare("2-2","22-", StringComparison.CurrentCulture) //1 What on earth is happening here? Our culture is en-US by the way. 回答1: As per the documentation: Character sets include ignorable characters. The Compare(String, String, StringComparison) method does not consider such characters when it performs a

In Java, which is faster - String.contains(“some text”) or Regex that looks for same text?

橙三吉。 提交于 2019-12-10 13:47:14
问题 As the title says, just looking for a string to match a client finishing sending data over a socket, so I might be looking for something like {"Message" : "END"} in a JSON string for example. A the most the strings will be a few hundred chars long. 回答1: They're both fast enough to be over before you know it. Better to go for the one that you can read more easily. But from forums, blogs contains is faster, but still negligible performance difference 回答2: I had tried both approaches and

Difference between ASCII comparison and string comparison

ぃ、小莉子 提交于 2019-12-10 13:16:11
问题 I am using C#. When I am comparing two char value its sending me correct output, like, '-'.CompareTo('!') //Its sending me positive value 12 means '-' > '!' is true But when I am comparing two string of same value its sending me different result "-".CompareTo("!") //Its sending me negative value -1 means "-" > "!" is false Can anyone please explain me why it is doing so ? Should not it be 'true' for both cases ? 回答1: String's Compare method is culture specific. That's why you get different

Constant strings address

自古美人都是妖i 提交于 2019-12-10 13:15:27
问题 I have several identical string constants in my program: const char* Ok() { return "Ok"; } int main() { const char* ok = "Ok"; } Is there guarantee that they are have the same address, i.e. could I write the following code? I heard that GNU C++ optimize strings so they have the same address, could I use that feature in my programs? int main() { const char* ok = "Ok"; if ( ok == Ok() ) // is it ok? ; } 回答1: There's certainly no guarantee, but it is a common (I think) optimization. The C++

Find number of characters mutual between two strings in C#

爷,独闯天下 提交于 2019-12-10 12:44:14
问题 I am looking for a method that will take two strings and return the number of characters that are common to both e.g.: "G010" & "G1820A" should return 3 as the G, 0 and 1 chars exist in both. If a char exists twice in both they should be counted separately as follows: "G12AA" & "GAA2" should return 4 as the G, A, A and 2 characters exist in both. Any help with this? Google searches haven't been too helpful thus far. 回答1: Okay, how about this, it has the advantage of maximising lazy evaluation

How to compare Unicode characters that “look alike”?

这一生的挚爱 提交于 2019-12-10 12:37:53
问题 I fall into a surprising issue. I loaded a text file in my application and I have some logic which compares the value having µ. And I realized that even if the texts are same the compare value is false. Console.WriteLine("μ".Equals("µ")); // returns false Console.WriteLine("µ".Equals("µ")); // return true In later line the character µ is copy pasted. However, these might not be the only characters that are like this. Is there any way in C# to compare the characters which look the same but are

Comparison of extra-large subsets of strings

别来无恙 提交于 2019-12-10 10:06:16
问题 Hi guys :) I really confused of one task :-/ There is one every-day file from 2000000 to 4000000 strings, which contains unique 15-symbol numbers line by line like this: 850025000010145 401115000010152 400025000010166 770025555010152 512498004158752 From beginning of current year you have some amount of such files accordingly. So I have to compare every line of today's file with all previous files from beginning of the year and return only that numbers which never meet before in all checked