Wcsstr no case sensitivity

Does anyone know how to use wcsstr

case insensitive in C? If it's important, I'll use it in the kernel driver.


source to share

1 answer

If you are programming on Windows, you can use the function StrStrI()


You cannot use it in a kernel driver, so you need to write it down as you see fit . In this example is used toupper()

and should be replaced with RtlUpcaseUnicodeChar

(as pointed out by Rup). To summarize, you need something like this:

char *stristr(const wchar_t *String, const wchar_t *Pattern)
      wchar_t *pptr, *sptr, *start;

      for (start = (wchar_t *)String; *start != NUL; ++start)
            while (((*start!=NUL) && (RtlUpcaseUnicodeChar(*start) 
                    != RtlUpcaseUnicodeChar(*Pattern))))

            if (NUL == *start)
                  return NULL;

            pptr = (wchar_t *)Pattern;
            sptr = (wchar_t *)start;

            while (RtlUpcaseUnicodeChar(*sptr) == RtlUpcaseUnicodeChar(*pptr))

                  if (NUL == *pptr)
                        return (start);

      return NULL;




All Articles