skip to Main Content

I’m working with .NET 8 and encountering an issue with character conversion in Turkish text. According to Turkish language rules, when converting uppercase ‘İ’ to lowercase, it should become ‘ı’. However, in my .NET 8 application, it converts ‘İ’ to ‘i’ instead. How can I ensure that .NET 8 handles this conversion correctly to ‘ı’?

.Net 8

var toLower = "Iı".ToLower();

// Output 
// iı

.NET Framework 4.7

var toLower = "Iı".ToLower();

// Output 
// ıı

2

Answers


  1. Use CultureInfo("tr-TR") in .NET 8 for the conversion.

    Refer the code below:

    using System;
    using System.Globalization;
    
    class Program
    {
        static void Main()
        {
            var turkishCulture = new CultureInfo("tr-TR");
            var text = "Iı";
            var toLower = text.ToLower(turkishCulture);
            Console.WriteLine(toLower); // Output: ıı
        }
    }
    

    Refer to the working .netfiddle here

    Login or Signup to reply.
  2. Implementation of these two methods in .NetFemeWork and .Net
    similar as shown below, both of which use CurrentCulture

    in .Net

     public string ToLower(CultureInfo? culture)
     {
         CultureInfo cult = culture ?? CultureInfo.CurrentCulture;
         return cult.TextInfo.ToLower(this);
     }
    

    in .NetFrameWork

    public string ToLower()
    {
        return ToLower(CultureInfo.CurrentCulture);
    }
    

    If you want to explicitly mention which culture to use, the code will be as follows

     var toLower = "Iı".ToLower(new CultureInfo("tr-TR"));
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search