How to get the length of text found with CurrentCulture?

Heiko 1,236 Reputation points
2024-07-26T11:23:17.18+00:00

Suppose I have a text "MaxGroßenIsHere". CurrentCulture is set to "de-DE" in my app. German has the character ß, which can often be written as ss, especially in computers. Therefore, "MaxGroßenIsHere".IndexOf("grossen", idx, StringComparison.CurrentCultureIgnoreCase) returns 3, which is correct.

Now I would like to highlight the text found in my app in color. Unfortunately, I only know the length of the text I am looking for, but not the length of the found text. That's why the I in "MaxGroßenIsHere" is also highlighted and the search for any further text starts with "sHere" instead of "IsHere".

It is a UWP app.

How can I determine the length of the text found?

Universal Windows Platform (UWP)
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,525 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,656 questions
{count} votes

Accepted answer
  1. Viorel 1.2L Reputation points
    2024-07-26T12:38:12.6033333+00:00

    If no better solutions, maybe you can use the result of IndexOf to extract various candidates, such as “G”, “Gr, “Gro, “Groß”, etc., until you find a match. You can use String.Compare(candicate, "grossen", StringComparison.CurrentCultureIgnoreCase). Then use the length of candidate.

    3 people found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful