Regex capitalize first letter every word, also after a special character like a dash

后端 未结 6 928
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-29 08:21

I use this #(\\s|^)([a-z0-9-_]+)#i for capitalize every first letter every word, i want it also to capitalize the letter if it\'s after a special mark like a da

6条回答
  •  星月不相逢
    2020-11-29 08:55

    this will make

    R.E.A.C De Boeremeakers

    from

    r.e.a.c de boeremeakers

    (?<=\A|[ .])(?[a-z])(?=[a-z. ])
    

    using

        Dim matches As MatchCollection = Regex.Matches(inputText, "(?<=\A|[ .])(?[a-z])(?=[a-z. ])")
        Dim outputText As New StringBuilder
        If matches(0).Index > 0 Then outputText.Append(inputText.Substring(0, matches(0).Index))
        index = matches(0).Index + matches(0).Length
        For Each Match As Match In matches
            Try
                outputText.Append(UCase(Match.Value))
                outputText.Append(inputText.Substring(Match.Index + 1, Match.NextMatch.Index - Match.Index - 1))
            Catch ex As Exception
                outputText.Append(inputText.Substring(Match.Index + 1, inputText.Length - Match.Index - 1))
            End Try
        Next
    

提交回复
热议问题