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

前端 未结 9 1484
無奈伤痛
無奈伤痛 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:32

    Not in "pure" regex, but most platform-specific implementations have a way to do it:

    For example, in python:

    import re
    re.compile(r'\b\w').sub(lambda x: x.group(0).upper(), 'hello')
    

    In this case we pass a callable lambda to the sub() method (rather than a replacement string) that will return the matching string upper cased. Most languages have some equivalent where you pass a callable as the 'replacement'.

    In VB.NET you can pass your 'replacement' lambda as Function (x) x.Value(0).ToString().ToUpper()

提交回复
热议问题