LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

case insensitive search for a string

I am using strstr() to search for a substring in a string. I now want the search to be case insensitive. Are there any built in functions for this, or what do I do? How about to turn an entire string from mixed case to upper case?
0 Kudos
Message 1 of 5
(3,404 Views)
You can't have the function ignore case, but you can convert the string into all upper or lower case with functions like toupper in the ANSI-C library.

For example:

char str[10] = "Cvi Rocks"
char upperStr[10];

for (i=0;i upperStr[i] = toupper(str[i]);

upperStr[strlen(str)] = "\0";

upperStr would then contain CVI ROCKS.

Best Regards,

Chris Matthews
National Instruments
0 Kudos
Message 2 of 5
(3,404 Views)
hello

Check out the stricmp() function.Here is what the help states:

"
This function compares two NUL-terminated strings. The comparison is based upon the value of the characters in the strings. Each character is interpreted as an unsigned char.

The comparison is not case-sensitive."

Hope this helps

Thanks

Bilal Durrani
NI
Bilal Durrani
NI
0 Kudos
Message 3 of 5
(3,404 Views)
Another approach is to use RegExpr_FindPatternInText() from regexpr.fp that
comes with CVI 6.0. It takes an argument (the 2nd one) that lets you specify
case-insensitivity, and the string you're searching for can be a regular
expression, for example:

x = RegExpr_FindPatternInText ("XYZ", 0, "abcxyz", -1, RegExpr_SearchForwards,
RegExpr_MatchSmallestNumChars, &mat, &pos,
&len);

"pos" returns the 0-based position of the match (i.e. 3 in this example) or -1
if no match was found.

Regular expressions are generally more flexible for text searching. If your
program controls the content of the sub-strings then they're a good solution.
However, if the sub-strings that you're searching for are supplied by another
source that may include rando
m meta-characters like *, [ or \ in them, then
uppercasing the strings as Chris suggested is a better way to go.
0 Kudos
Message 4 of 5
(3,404 Views)
Thanks. I am only using CVI 5.5, but should probably move up. I already solved this with char by char toupper from an earlier post, but thanks anyway.
0 Kudos
Message 5 of 5
(3,404 Views)