标题后的大写字母

use*_*932 1 .net c# asp.net string

是否存在.net 错误,导致以下代码将大写S给定了"Ben’S Pies"

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Globalization;

namespace Rextester
{
    public class Program
    {
        public static void Main(string[] args)
        {
        string value = "ben’s pies";
        string titleCase = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(value);
        Console.WriteLine(titleCase);    
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

您可以在以下位置查看输出:https : //rextester.com/(我尝试过的地方)。

Dmi*_*nko 7

如果打印的转储value

  string value = "ben’s pies";

  Console.Write(string.Join(" ", value.Select(c => ((int)c).ToString("x4"))));
Run Code Online (Sandbox Code Playgroud)

你会得到

0062 0065 006e 2019 0073 0020 0070 0069 0065 0073

现在,让我们来看看Unicode U + 2019

https://www.fileformat.info/info/unicode/char/2019/index.htm

而且我们看到,不是APOSTROPH,但“右单引号(U + 2019)。” 这就是为什么ToTitleCase它能正确工作的原因(它在标点符号后将单词大写-引号)。要修改示例,请用撇号代替引号:

 string value = "ben's pies";

 // Ben's Pies
 string titleCase = CultureInfo.GetCultureInfo("en-US").TextInfo.ToTitleCase(value);
Run Code Online (Sandbox Code Playgroud)