I'm trying to use IndexOf
as given in the example here:
https://msdn.microsoft.com/en-us/library/k8b1470s(v=vs.110).aspx
If you scroll down it shows the example:
string s1 = "ani\u00ADmal";
string s2 = "animal";
// Find the index of the soft hyphen.
Console.WriteLine(s1.IndexOf("\u00AD"));
Console.WriteLine(s2.IndexOf("\u00AD"));
I am trying to execute that from Main(string[] args)
and I get the compilation error, IndexOf
is culture aware and missing a string comparison argument." I have imported using System;
and using System.IO;
and I'm using Visual Studio on a Mac. Am I missing something?
EDIT: Alright, the explanation of the problem can be found under "remarks":
This method performs a word (case-sensitive and culture-sensitive) search using the current culture. The search begins at the first character position of this instance and continues until the last character position.
Character sets include ignorable characters, which are characters that are not considered when performing a linguistic or culture-sensitive comparison. In a culture-sensitive search, if value contains an ignorable character, the result is equivalent to searching with that character removed. If value consists only of one or more ignorable characters, theIndexOf(String) method always returns 0 (zero) to indicate that the match is found at the beginning of the current instance. In the following example, the IndexOf(String) method is used to find three substrings (a soft hyphen (U+00AD), a soft hyphen followed by "n", and a soft hyphen followed by "m") in two strings. Only one of the strings contains a soft hyphen. If the example is run on the .NET Framework 4 or later, in each case, because the soft hyphen is an ignorable character, the result is the same as if the soft hyphen had not been included in value. When searching for a soft hyphen only, the method returns 0 (zero) to indicate that it has found a match at the beginning of the string.