Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore case and compare in C# [duplicate]

How to convert the string to uppercase before performing a compare, or is it possible to compare the string by ignoring the case

 if (Convert.ToString(txt_SecAns.Text.Trim()).ToUpper() == 
     Convert.ToString(hidden_secans.Value).ToUpper())
like image 646
Murthy Avatar asked Nov 23 '11 13:11

Murthy


People also ask

How do you ignore case in comparison string?

The equalsIgnoreCase() method compares two strings, ignoring lower case and upper case differences. This method returns true if the strings are equal, and false if not. Tip: Use the compareToIgnoreCase() method to compare two strings lexicographically, ignoring case differences.

How do you make a case insensitive in C program?

How to make strcmp/strncmp case-insensitive in C/C++ To make strcmp case-insensitive, use strcasecmp from #include <strings. h> . strcasecmp can be used in exactly the same way as strcmp.

Does strcmp ignore case?

The strcasecmp() function compares, while ignoring differences in case, the string pointed to by string1 to the string pointed to by string2. The string arguments to the function must contain a NULL character (\0) marking the end of the string.

Is Memcmp case insensitive?

The _memicmp function compares the first count characters of the two buffers buffer1 and buffer2 byte by byte. The comparison is not case-sensitive.


1 Answers

use this:

var result = String.Compare("AA", "aa", StringComparison.OrdinalIgnoreCase);

String.Compare Method (String, String, Boolean)

like image 93
Davide Piras Avatar answered Sep 29 '22 05:09

Davide Piras