string-comparison

Check if string is a punctuation character

落爺英雄遲暮 提交于 2019-11-27 15:31:01
Let's say I have a String array that contains some letters and punctuation String letter[] = {"a","b","c",".","a"}; In letter[3] we have "." How can I check if a string is a punctuation character? We know that there are many possible punctuation characters (,.?! etc.) My progress so far: for (int a = 0; a < letter.length; a++) { if (letter[a].equals(".")) { //===>> i'm confused in this line System.out.println ("it's punctuation"); } else { System.out.println ("just letter"); } } Karthik T Do you want to check more punctuations other than just . ? If so you can do this. String punctuations = ".

Is it better to compare strings using toLowerCase or toUpperCase in JavaScript?

本秂侑毒 提交于 2019-11-27 14:42:27
问题 I'm going through a code review and I'm curious if it's better to convert strings to upper or lower case in JavaScript when attempting to compare them while ignoring case. Trivial example: var firstString = "I might be A different CASE"; var secondString = "i might be a different case"; var areStringsEqual = firstString.toLowerCase() === secondString.toLowerCase(); or should I do this: var firstString = "I might be A different CASE"; var secondString = "i might be a different case"; var

Using == or Equals for string comparison

我的未来我决定 提交于 2019-11-27 14:02:59
问题 In some languages (e.g. C++) you can't use operators like == for string comparisons as that would compare the address of the string object, and not the string itself. However, in C# you can use == to compare strings, and it will actually compare the content of the strings. But there are also string functions to handle such comparisons, so my question is; should you? Given two strings: string aa = "aa"; string bb = "bb"; Should you compare them like this: bool areEqual = (aa == bb); Or should

C++ Compare char array with string

萝らか妹 提交于 2019-11-27 12:36:55
I'm trying to compare a character array against a string like so: const char *var1 = " "; var1 = getenv("myEnvVar"); if(var1 == "dev") { // do stuff } This if statement never validates as true... when I output var1 it is "dev", I was thinking maybe it has something to do with a null terminated string, but the strlen of "dev" and var1 are equal... I also thought maybe var1 == "dev" was comparing "dev" against the memory location of var1 instead of the value. *var1 == "dev" results in an error.... tried many things, probably a simple solution for the saavy c++ developer (I havent coded c++ in a

Why does the default string comparer fail to maintain transitive consistency?

守給你的承諾、 提交于 2019-11-27 11:48:10
I know this issue has been noted before , more or less concisely, but I still create this new thread because I ran into the issue again when writing a unit test. The default string comparison (that is the culture-dependent case-sensitive comparison that we get with string.CompareTo(string) , Comparer<string>.Default , StringComparer.CurrentCulture , string.Compare(string, string) and others) violates transitivity when the strings contain hyphens (or minus signs, I am talking about plain U+002D characters). Here is a simple repro: static void Main() { const string a = "fk-"; const string b = "

Could string comparisons really differ based on culture when the string is guaranteed not to change?

大城市里の小女人 提交于 2019-11-27 11:25:33
问题 I'm reading encrypted credentials/connection strings from a config file. Resharper tells me, "String.IndexOf(string) is culture-specific here" on this line: if (line.Contains("host=")) { _host = line.Substring(line.IndexOf( "host=") + "host=".Length, line.Length - "host=".Length); ...and so wants to change it to: if (line.Contains("host=")) { _host = line.Substring(line.IndexOf("host=", System.StringComparison.Ordinal) + "host=".Length, line.Length - "host=".Length); The value I'm reading

Comparing a string with the empty string (Java)

时间秒杀一切 提交于 2019-11-27 11:21:24
I have a question about comparing a string with the empty string in Java. Is there a difference, if I compare a string with the empty string with == or equals ? For example: String s1 = "hi"; if (s1 == "") or if (s1.equals("")) I know that one should compare strings (and objects in general) with equals , and not == , but I am wondering whether it matters for the empty string. s1 == "" is not reliable as it tests reference equality not object equality (and String isn't strictly canonical). s1.equals("") is better but can suffer from null pointer exceptions. Better yet is: "".equals(s1) No null

C# - Compare String Similarity [duplicate]

為{幸葍}努か 提交于 2019-11-27 11:14:38
Possible Duplicate: Are there any Fuzzy Search or String Similarity Functions libraries written for C#? What is the best way to compare 2 strings to see how similar they are? Examples: My String My String With Extra Words Or My String My Slightly Different String What I am looking for is to determine how similar the first and second string in each pair is. I would like to score the comparison and if the strings are similar enough, I would consider them a matching pair. Is there a good way to do this in C#? Marty Neal static class LevenshteinDistance { public static int Compute(string s, string

Is == in PHP a case-sensitive string comparison?

心不动则不痛 提交于 2019-11-27 11:01:29
问题 I was unable to find this on php.net. Is the double equal sign ( == ) case sensitive when used to compare strings in PHP? 回答1: Yes, == is case sensitive. You can use strcasecmp for case insensitive comparison 回答2: Yes, but it does a comparison byte-by-byte. If you're comparing unicode strings, you may wish to normalize them first. See the Normalizer class. Example (output in UTF-8): $s1 = mb_convert_encoding("\x00\xe9", "UTF-8", "UTF-16BE"); $s2 = mb_convert_encoding("\x00\x65\x03\x01", "UTF

String Comparison Using Inequalities in Excel

白昼怎懂夜的黑 提交于 2019-11-27 08:04:36
问题 Can someone provide a reference to how excel compares strings using inequality operators in Excel? I have found some unexpected behavior: In the below examples, the first two columns are strings, column C is of the expression =A2<B2 , the third column is the expected behavior, and the final column is whether the expected behavior matches the actual. Comparison Benchmark Is A < B? Expected Pass? Q1 2009 Q4 2012 TRUE TRUE TRUE Q2 2009 Q4 2012 TRUE TRUE TRUE Q3 2009 Q4 2012 TRUE TRUE TRUE Q4