Regular Expression help

  • Thread starter Thread starter llihp
  • Start date Start date
L

llihp

I'm trying to turn text like this:

A test to turn [text like this] into some [other text].

into this:

A test to turn [TextLikeThis] into some [OtherText].

I can get an expression that will match the text in brackets, but I can't
work out how to sub-group so I can capitalise each word and remove the
spaces.

I'm matching the text in brackets using:

\[(\w+\s{0,})+\]

Any help gratefully received!!!
 
I am really bad at regEx, but here is a solution that comes to mind.

///
'This will have the text in the brackets
Dim txt_InBrackets As String

'This will have the final formatted string
Dim TitleCaseText As String
Dim arrWords() As String
Dim i As Integer

'Convert Text to Title case
txt_InBrackets = StrConv(txt_InBrackets, VbStrConv.ProperCase)

'Split the Title case string into individual words
arrWords = Split(txt_InBrackets, " ")

For i = 0 To UBound(arrWords)
'Loop through the array to concatenate the words
TitleCaseText &= arrWords(i)
Next

Console.WriteLine(TitleCaseText)

\\\

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top