是否可以使用正则表达式将每个单词的第一个字符大写?
我将在VB.net(SSIS)中使用它
编辑:下面添加的VB.NET代码
原文链接:/vb/255424.htmlDim input As String = "The quick brown fox jumps over the lazy dog" Dim pattern As String = "\b(\w|['-])+\b" ' With lambda support: Dim result As String = Regex.Replace(input,pattern,_ Function (m) m.Value(0).ToString().ToUpper() & m.Value.Substring(1))
如果你不能使用lambdas,那么使用MatchEvaluator代替:
Dim evaluator As MatchEvaluator = AddressOf TitleCase Dim result As String = Regex.Replace(input,evaluator) Public Function TitleCase(ByVal m As Match) As String Return m.Value(0).ToString().ToUpper() & m.Value.Substring(1) End Function
从MS Word格式的意义上来说,这不是真正的标题案例,但足够接近.
您没有指定语言,但在C#中您可以这样做:
string input = "The quick brown fox jumps over the lazy dog"; string pattern = @"\b(\w|['-])+\b"; string result = Regex.Replace(input,m => m.Value[0].ToString().ToUpper() + m.Value.Substring(1));