If you want to use the US culture to perform casing, you need to do so consistently. Instead, you're currently lower-casing the string in the current culture, which is causing the problem.
Instead, use the same TextInfo
for both the lower-casing and title-casing operations:
sing System;
using System.Globalization;
class Program
{
static void Main()
{
CultureInfo.CurrentCulture = new CultureInfo("tr-TR");
var text = "VIENNA IS A VERY BEAUTIFUL CAPITAL CITY.";
// Original code in the question
var title1 = new CultureInfo("en-US", false).TextInfo.ToTitleCase(text.ToLower());
Console.WriteLine(title1); // Contains Turkish "i" characters
// Corrected code
var textInfo = new CultureInfo("en-US", false).TextInfo;
var lower = textInfo.ToLower(text);
var title2 = textInfo.ToTitleCase(lower);
Console.WriteLine(title2); // Correct output
}
}
(This is broadly equivalent to Jens' answer, but I prefer to use TextInfo
for both operations if you're using it for either, just for consistency.)