string-comparison

msbuild string upper case comparison

Hi, i have the following code in my build-file: <Error Text="Some Text" condition="'$(StringName)' != 'Test'/> It causes an error if the condition is not match. When $(StringName) is 'test' the condition is not met so the error is executed. How can I change the condition, that 'test' als meets the condition? Is there any upper-case ...

partial string comparision in php

i have stored two ip address values in two strings a = '116.95.123.111' b = '116.95.122.112' i just want to compare the first two parts of ip address i.e 116.95 part in the two strings and as it is same in both the strings my comparison should return true. how to do this partial string comparison in PHP? ...

Constant strings address

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 progr...

Cast collation of nvarchar variables in t-sql

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 a...

Sort Map<String, Object> by keys with IgnoreCase?

Well, I tested TreeMap but it doesn't take in account IgnoreCase on string comparision. I need to order lexicographically and ignoring case. Is there any other way? Thanks, that works (TreeMap (Comparator c)). However, I have another question: public final Comparator<Object> STR_IGN_CASE_COMP = new Comparator<Object>() { public in...

percentage-based string comparison in php

Hi, I'm looking for a library in PHP that will allow me to compare two strings, and determine if they similar. For example: apple apple 100% apple aple 80% and so forth. any ideas? ...

Word by word comparison of two strings

Hello, I need to do Word by word comparison of two strings. Something like diff, but for words, not for lines. Like it is done in wikipedia http://en.wikipedia.org/w/index.php?title=Horapollo&amp;action=historysubmit&amp;diff=21895647&amp;oldid=21893459 In result I want return the two arrays of indexes of words, which are different i...

Comparing character arrays with an == operator in C

I know that the correct way to compare "strings" in C is by using strcmp, but now I tried comparing some character arrays with the == operator, and got some strange results. Take a look at the following code: int main() { char *s1 = "Andreas"; char *s2 = "Andreas"; char s3[] = "Andreas"; char s4[] = "Andreas"; cha...

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

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 ab...

String.comparison performance (with trim)

I need to do alot of high-performance case-insensitive string comparisons and realized that my way of doing it .ToLower().Trim() was really stupid due do all the new strings being allocated So I digged around a little and this way seems preferable: String.Compare(txt1,txt2, StringComparison.OrdinalIgnoreCase) The only problem here...

String comparison equivalents

I believe these 2 lines are equivalent but after running into a strange issue I no longer believe this to be the case. String mimeType = context.Request.ContentType; (String.Compare("text/xml", mimeType, true) == 0)) is the same as : context.Request.ContentType.ToLower().Equals("text/xml") Are their implementations in the CLR any d...

Using == or Equals for string comparison

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, s...

Is StringComparer.CurrentCulture the right choice to use in this case?

I have a list of UTF-8 strings that I want to sort using Enumerable.OrderBy. The strings may contain any number of character sets - e.g., English, German, and Japanese, or a mix of them, even. For example, here is a sample input list: ["東京","North 東京", "München", "New York", "Chicago", "大阪市"] I am confused as to whether using String...

Sort months ( with strings ) algorithm

I have this months array: ["January", "March", "December" , "October" ] And I want to have it sorted like this: ["January", "March", "October", "December" ] I'm currently thinking in a "if/else" horrible cascade but I wonder if there is some other way to do this. The bad part is that I need to do this only with "string" ( that i...

case-insensitive comparison of two TCHAR's

What is a good way to compare two individual characters (either char or UTF-16 wchar_ts) ignoring case? A trivial implementation would be upper- or lowercasing both. Is one of these considered better, or are there other methods? I understand that a completely correct comparison is not possible with all details of Unicode. The comparis...

Unicode characters causing issues in SQL Server 2005 string comparison.

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 ...

Comparing strings with tolerance

Hi! I'm looking for a way to compare a string with an array of strings. Doing an exact search is quite easy of course, but I want my program to tolerate spelling mistakes, missing parts of the string and so on. Is there some kind of framework which can perform such a search? I'm having something in mind that the search algorithm will r...

What is the best flexible means of comparing version numbers?

I am working with a script to compare version numbers for installed and available applications. I would, on a normal basis, use simple comparison operators. Since I am building this application in a PHP 5.3 environment, I have considered the use of version_compare(), but that doesn't seem to suit my needs as cleanly as I would like. The...

PHP substr and strlen alternative

I heard that in PHP there are some alternatives for the functions substr() and strlen() which handles safer bits. Is this true and if it is then what are those functions? I heard that it is based on the function strcmp() but I don't see directly how can I use it. ...

String Comparison containing hyphens not matching

I have a method in a url rewriting module that looks like this public bool Match(Uri url) { string x = url.PathAndQuery.ToLowerInvariant(); string y = RuleData.ToLowerInvariant(); return x.Contains(y); } However, it is not returning true for the following values: x = "/xx09-02-09xx"; y = "09-02-09"; but if I writ...