有没有办法让我将 O'Reilly 转换为 O'Reilly?

Is there a way for me to convert O'reilly to O'Reilly?

我想以首字母大写显示名称,并正确转换带连字符的名称(例如 O'Reilly)。

现在,当我使用 ToUpperCase 函数时,我得到 "O'reilly",这不是我想要的。

这是我正在使用的函数:

@functions
{
    public static class TextConvert
    {
        public static string ToTitleCase(string s)
        {
            s = s.ToLower();
            return Regex.Replace(s, @"(^\w)|(\s\w)",b => b.Value.ToUpper());
        }
    }
}

我该怎么做,考虑像 O'Reilly 这样的案例?

仅靠技术工具无法做到这一点。有些非洲名字根本不以大写字母开头。正如您在此实用程序 (http://www.johncardinal.com/tmgutil/capitalizenames.htm) 中看到的那样,最简单的方法是实际维护一个异常列表并将您的名字与其匹配。

你可以试试

var titlecase = PrintName("o'riley");

调用这个函数

Public static string PrintName(string StrValue)//pass here - o'riley
        {
            if (!string.IsNullOrEmpty(StrValue))
            {
                return Regex.Replace(CultureInfo.CurrentCulture.TextInfo.ToTitleCase(StrValue.ToLower()),
                 "['-](?:.)", m => m.Value.ToUpperInvariant());
            }
            else
            {
                return "Something meaningful message";
            }
        }