Search code examples
c#xamarin.androidmono

String.IndexOf fails on Xamarin.Android (Mono) but not on .NET Framework


The line below returns -1 (incorrect) on Xamarin.Android and 2 (correct) on .NET Framework:

"ビューアー".IndexOf("ー")

Looking in the Mono source code, SimpleCollator.cs, I can see that character "ー" (0x30FC) has special handling.

Is there a way to make this line work properly in Xamarin.Android?


Solution

  • Different from .NET Framework . In Xamarin (iOS and Android) , we need to implement localization to support multiple languages . In your case , the easiest way is to ignore the Language and Area .

    var index = "ビューアー".IndexOf("ー",StringComparison.OrdinalIgnoreCase);
    

    For more details about localization you could refer Xamarin.Android Localization .