I am trying to find the index of a substring in a string that matches another string under a specific culture (provided from a System.CultureInfo).
For example the string "ass" matches the substring "aß" in "straße" under a German culture.
I can find the index of the start of the match using
culture.CompareInfo.IndexOf(value, substring);
but without resorting to brute force, is there an easy way of identifying that 2 characters were matched, and not 3?
You call the Substring(Int32) method to extract a substring from a string that begins at a specified character position and ends at the end of the string. The starting character position is a zero-based; in other words, the first character in the string is at index 0, not index 1.
In C#, IndexOf() method is a string method. This method is used to find the zero-based index of the first occurrence of a specified character or string within the current instance of the string. The method returns -1 if the character or string is not found.
In C#, Equals(String, String) is a String method. It is used to determine whether two String objects have the same value or not. Basically, it checks for equality. If both strings have the same value, it returns true otherwise returns false.
If you use a capture group, you can capture the exact match that was found, and from that you can determine how many characters were matched.
I'm a bit timestressed right now to give an example, so I hope you can figure it out from my description.
Perhaps I'll ammend my answer later.
Dave
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With