case-insensitive

Is there a C# case insensitive equals operator?

随声附和 提交于 2019-11-26 15:04:04
I know that the following is case sensitive: if (StringA == StringB) { So is there an operator which will compare two strings in an insensitive manner? Try this: string.Equals(a, b, StringComparison.CurrentCultureIgnoreCase); The best way to compare 2 strings ignoring the case of the letters is to use the String.Equals static method specifying an ordinal ignore case string comparison. This is also the fastest way, much faster than converting the strings to lower or upper case and comparing them after that. I tested the performance of both approaches and the ordinal ignore case string

Case insensitive string comparison C++ [duplicate]

為{幸葍}努か 提交于 2019-11-26 14:37:37
问题 This question already has an answer here: Case-insensitive string comparison in C++ [closed] 31 answers I know there are ways to do case ignore comparison that involve iterating through strings or one good one on SO needs another library. I need to put this on other computers that might not have it installed. Is there a way to use the standard libraries to do this? Right now I am just doing... if (foo == "Bar" || foo == "bar") { cout << "foo is bar" << endl; } else if (foo == "Stack Overflow"

Case insensitive replace

隐身守侯 提交于 2019-11-26 14:21:10
What's the easiest way to do a case-insensitive string replacement in Python? Blair Conrad The string type doesn't support this. You're probably best off using the regular expression sub method with the re.IGNORECASE option. >>> import re >>> insensitive_hippo = re.compile(re.escape('hippo'), re.IGNORECASE) >>> insensitive_hippo.sub('giraffe', 'I want a hIPpo for my birthday') 'I want a giraffe for my birthday' import re pattern = re.compile("hello", re.IGNORECASE) pattern.sub("bye", "hello HeLLo HELLO") # 'bye bye bye' viebel In a single line: import re re.sub("(?i)hello","bye", "hello HeLLo

Win32 File Name Comparison

此生再无相见时 提交于 2019-11-26 14:08:24
问题 Does anyone know what culture settings Win32 uses when dealing with case-insensitive files names? Is this something that varies based on the user's culture, or are the casing rules that Win32 uses culture invariant? 回答1: An approximate answer is at Comparing Unicode file names the right way. Basically, the recommendation is to uppercase both strings (using CharUpper, CharUpperBuff, or LCMapString), then compare using a binary comparison (i.e. memcmp or wmemcmp, not CompareString with an

Case insensitive regular expression without re.compile?

被刻印的时光 ゝ 提交于 2019-11-26 14:03:55
In Python, I can compile a regular expression to be case-insensitive using re.compile : >>> s = 'TeSt' >>> casesensitive = re.compile('test') >>> ignorecase = re.compile('test', re.IGNORECASE) >>> >>> print casesensitive.match(s) None >>> print ignorecase.match(s) <_sre.SRE_Match object at 0x02F0B608> Is there a way to do the same, but without using re.compile . I can't find anything like Perl's i suffix (e.g. m/test/i ) in the documentation. Michael Haren Pass re.IGNORECASE to the flags param of search , match , or sub : re.search('test', 'TeSt', re.IGNORECASE) re.match('test', 'TeSt', re

Case insensitive string as HashMap key

好久不见. 提交于 2019-11-26 12:51:24
I would like to use case insensitive string as a HashMap key for the following reasons. During initialization, my program creates HashMap with user defined String While processing an event (network traffic in my case), I might received String in a different case but I should be able to locate the <key, value> from HashMap ignoring the case I received from traffic. I've followed this approach CaseInsensitiveString.java public final class CaseInsensitiveString { private String s; public CaseInsensitiveString(String s) { if (s == null) throw new NullPointerException(); this.s = s; } public

Contains case insensitive

落花浮王杯 提交于 2019-11-26 12:43:50
I have the following: if (referrer.indexOf("Ral") == -1) { ... } What I like to do is to make Ral case insensitive, so that it can be RAl , rAl , etc. and still match. Is there a way to say that Ral has to be case-insensitive? Add .toLowerCase() after referrer . This method turns the string in a lower case string. Then, use .indexOf() using ral instead of Ral . if (referrer.toLowerCase().indexOf("ral") === -1) { The same can also be achieved using a Regular Expression (especially useful when you want to test against dynamic patterns): if (!/Ral/i.test(referrer)) { // ^i = Ignore case flag for

How to replace case-insensitive literal substrings in Java

一笑奈何 提交于 2019-11-26 12:13:42
Using the method replace(CharSequence target, CharSequence replacement) in String, how can I make the target case-insensitive? For example, the way it works right now: String target = "FooBar"; target.replace("Foo", "") // would return "Bar" String target = "fooBar"; target.replace("Foo", "") // would return "fooBar" How can I make it so replace (or if there is a more suitable method) is case-insensitive so that both examples return "Bar"? lukastymo String target = "FOOBar"; target = target.replaceAll("(?i)foo", ""); System.out.println(target); Output: Bar It's worth mentioning that replaceAll

How can I have case insensitive URLS in Spring MVC with annotated mappings

試著忘記壹切 提交于 2019-11-26 12:13:32
问题 I have annotated mappings working great through my spring mvc web app, however, they are case sensitive. I cannot find a way to make them case insensitive. (I\'d love to make this happen within Spring MVC, rather than redirecting traffic somehow) 回答1: Spring 4.2 will support case-insensitive path matching. You can configure it as follows: @Configuration public class WebConfig extends WebMvcConfigurerAdapter { @Override public void configurePathMatch(PathMatchConfigurer configurer) {

Case insensitive &#39;in&#39; - Python

↘锁芯ラ 提交于 2019-11-26 11:44:17
I love using the expression if 'MICHAEL89' in USERNAMES: ... where USERNAMES is a list Is there any way to match items with case insensitivity or do I need to use a custom method? Just wondering if there is need to write extra code for this. Thanks to everyone! if 'MICHAEL89' in (name.upper() for name in USERNAMES): ... Alternatively: if 'MICHAEL89' in map(str.upper, USERNAMES): ... Or, yes, you can make a custom method. Alex Martelli I would make a wrapper so you can be non-invasive. Minimally, for example...: class CaseInsensitively(object): def __init__(self, s): self.__s = s.lower() def _