string-comparison

Objective-C constants: NSString comparison using ==?

▼魔方 西西 提交于 2019-12-01 06:44:38
The discussions I found about setting NSString constants made me code it the following way: .h file: extern NSString * const kSectionHeaders; .m file: NSString * const kSectionHeaders = @"header"; As the program runs, it has to test words from a text file against a series of NSString constants. I read memory comparison should work when setting function like stated above: if (property == kSectionHeaders) {...} Doesn't work tough :( The following works, but it was described as a bad solution (slower, what else?): if ([property isEqualToString:kSectionHeaders]){...} I feel I've done something

Objective-C constants: NSString comparison using ==?

夙愿已清 提交于 2019-12-01 05:32:18
问题 The discussions I found about setting NSString constants made me code it the following way: .h file: extern NSString * const kSectionHeaders; .m file: NSString * const kSectionHeaders = @"header"; As the program runs, it has to test words from a text file against a series of NSString constants. I read memory comparison should work when setting function like stated above: if (property == kSectionHeaders) {...} Doesn't work tough :( The following works, but it was described as a bad solution

Why does a less than or more than comparison in PHP of two strings in the date format of “YYYY-MM-DD” work even though they are strings?

瘦欲@ 提交于 2019-12-01 04:06:27
I am working on a section of PHP code for a project that compares a date in the YYYY-MM-DD format to the current date to see if it is less than the current date. At different points in the code two different methods were used for making this comparison. The first used get_timestamp() on the dates and ran the comparison off of the timestamps. In another place it just compared the string of the date to the output from date("Y-m-d") . My expectation was that the comparison of two date strings would not provide a correct response. However, when I set up several test cases I got the output expected

Culture-aware string comparison for Umlaute

一个人想着一个人 提交于 2019-12-01 03:06:11
问题 I need to compare two strings in German language to check if they are equal and only differ in the use of umlaute. E.g. "Jörg" should be the same as "Joerg". So I tried: var ci = new CultureInfo("de-DE"); int compareResult = ci.CompareInfo.Compare("jörg", "joerg", CompareOptions.IgnoreNonSpace); as well as int compareResult = String.Compare("jörg", "joerg", true, ci); (or are those two equal anyway?) However, this does not work and will return 1 . It is the same for all umlauts ö,ü and ä. If

Why does a less than or more than comparison in PHP of two strings in the date format of “YYYY-MM-DD” work even though they are strings?

谁说胖子不能爱 提交于 2019-12-01 01:44:20
问题 I am working on a section of PHP code for a project that compares a date in the YYYY-MM-DD format to the current date to see if it is less than the current date. At different points in the code two different methods were used for making this comparison. The first used get_timestamp() on the dates and ran the comparison off of the timestamps. In another place it just compared the string of the date to the output from date("Y-m-d") . My expectation was that the comparison of two date strings

PHP nearest string comparison [duplicate]

假如想象 提交于 2019-12-01 01:34:52
Possible Duplicate: String similarity in PHP: levenshtein like function for long strings I have my subject string $subj = "Director, My Company"; and a list of multiple strings to be compared: $str1 = "Foo bar"; $str2 = "Lorem Ipsum"; $str3 = "Director"; What I want to achieve here is to find the nearest string related to $subj . Is it possible to do it? hek2mgl The levenshtein() function will do what you expect. The Levenshtein algorithm calculates the number of insert and replace actions being required to transform some string into another. The result is called an edit distance . The

Compare result from hexdigest() to a string

那年仲夏 提交于 2019-11-30 20:31:43
I've got a generated MD5-hash, which I would like to compare to another MD5-hash from a string. The statement below is false, even though they look the same when you print them and should be true. hashlib.md5("foo").hexdigest() == "acbd18db4cc2f85cedef654fccc4a4d8" Google told me that I should encode the result from hexdigest() , since it doesn't return a string. However, the code below doesn't seem to work either. hashlib.md5("foo").hexdigest().encode("utf-8") == "foo".encode("utf-8") Python 2.7, .hexdigest() does return a str >>> hashlib.md5("foo").hexdigest() ==

string1 >= string2 not implemented in Linq to SQL, any workarround?

扶醉桌前 提交于 2019-11-30 18:48:48
anyones knows how to do this? Edit: I am trying to do >=. I correct the Title. JaredPar string1 >= string2 is not supported in C# Linq To Sql. The String class does not override the >= operator at all. It only overrides the != and == operators. You can verify this by trying to compile the following method public static void Example() { int val = "foo" >= "bar"; } If you want to compare to Strings in LinqToSql you should be able to use the static String.Compare(string,string) method. If you're looking for => which would normally be written as >= then you cannot do this directly with strings.

How Java String pool works when String concatenation?

北战南征 提交于 2019-11-30 16:34:20
Beware: I'm not trying to compare if the characters are equals. Because I know how to use the String.equals() method. This question is about String reference I was studying for the OCA exam when I started to learn about the class String and it properties as immutability, etc. According to what I read or may understand about String pool is that when a string is created Java stores this object on what they call String pool and if a new string is created with the same value it is going to make reference to the string on the String pool except is the case we use the new keyword as this creates a

how to compare two strings in javascript if condition

我与影子孤独终老i 提交于 2019-11-30 16:08:08
问题 I'm having trouble recalling how to compare these two strings in an if statement. What I'm string to do is check if my variable compare equals page1 or page2 if not, go to the else statement. var compare = "page3"; if (compare === "page1" || "page2") { document.body.innerHTML = "github url"; } else { document.body.innerHTML = "non-github url"; } 回答1: You could check every option. if (compare === "page1" || compare === "page2") { Or you could use an array and check with an existential