This is just a guess - could it be because your program is running in a
Danish locale? The letter combination "aa" is interpreted as the Danish
letter "Ã¥"?
That is it.
using System;
using System.Globalization;
using System.Threading;
namespace E
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("7 mpaa".IndexOf("mpa"));
Console.WriteLine("7 mpaa".IndexOf("mpa",
StringComparison.InvariantCulture));
Console.WriteLine("7 mpaa".IndexOf("mpa",
StringComparison.Ordinal));
Thread.CurrentThread.CurrentCulture =
CultureInfo.InvariantCulture;
Console.WriteLine("7 mpaa".IndexOf("mpa"));
Console.ReadKey(true);
}
}
}
outputs:
da-DK
-1
2
2
2
here.
The docs also state:
<quote>
Remarks
Index numbering starts from zero.
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.
Notes to Callers
As explained in Best Practices for Using Strings in the .NET Framework, we
recommend that you avoid calling string comparison methods that substitute
default values and instead call methods that require parameters to be
explicitly specified. To find the first index of a substring within a
string instance by using the comparison rules of the current culture, call
the IndexOf(String, StringComparison) method overload with a value of
StringComparison::CurrentCulture for its comparisonType parameter.
</quote>