Add some spaces in “BozzoTheClown”

I want to add some spaces in “BozzoTheClown” kind of string to get:

“Bozzo The Clown”.

Ideas (instead of loop into the string and add a space if the letter is from uppercase A…Z) ?

Regex replace?

1 Like

Thank you Stephan, seems a good solution… and a nice screen shot !

Public Function ExplodeCamels(words As String) As String

  Var re As New RegEx
  re.SearchPattern = "(([a-z])([A-Z]))"
  re.ReplacementPattern = "$2 $3"
  re.Options.CaseSensitive = True
  re.Options.ReplaceAllMatches = True
  
  Return re.Replace(words)
  
End Function

image

2 Likes

Thank you Rick:

I have a visit of a friend and so I do not explored RegEx before I read your addition (code).

Now I only have to copy / paste it in my project !

1 Like
Public Function ExplodeCamels(words As String) As String

  Var re As New RegEx
  re.SearchPattern = "([a-z])([A-Z])"
  re.ReplacementPattern = "$1 $2"
  re.Options.CaseSensitive = True
  re.Options.ReplaceAllMatches = True
  
  Return re.Replace(words)
  
End Function

^^^ After a tiny clean up (removed residuals from my first test)

2 Likes