How to get the length of text found with CurrentCulture?

Heiko 1,311 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?

Developer technologies | Universal Windows Platform (UWP)
Windows development | Windows API - Win32
Developer technologies | C#
Developer technologies | 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.
{count} votes

Answer accepted by question author
  1. Viorel 125.2K 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

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.