How to uppercase the first character of each word using a regex in VB.NET?

前端 未结 9 1480
無奈伤痛
無奈伤痛 2020-12-06 19:19

Is it possible to uppercase the first character of each word using regex?

I\'m going to be using this in VB.net (SSIS)

相关标签:
9条回答
  • 2020-12-06 19:41

    Why not just use the inbuilt TextInfo.ToTitleCase() method already in the .NET Framework?

    string capitalized = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase("this string should be capitalized!");
    
    0 讨论(0)
  • 2020-12-06 19:44
     s/\b(\w+)\b/ucfirst($1)/ge
    
    0 讨论(0)
  • 2020-12-06 19:47

    .NET has builtin support for this. See TextInfo.ToTitleCase for documentation.

    My code contains some extension methods for C#. I assume VB.NET has those too, but I do not know VB.NET well enough to convert them myself.

    public static class StringExtensions {
        public static string ToTitleCase(this string value) {
            return value.ToTitleCase(CultureInfo.InvariantCulture);
        }
    
        public static string ToTitleCase(this string value, CultureInfo culture) {
            return value.ToTitleCase(culture.TextInfo);
        }
    
        public static string ToTitleCase(this string value, TextInfo textInfo) {
            return textInfo.ToTitleCase(value);
        }
    }
    
    0 讨论(0)
提交回复
热议问题