Lowercase/Uppercase preserving quotes

Hi,

I was trying to create a simple method to convert a string to lowercase/uppercase characters preserving the quotes, that it, what it is included in quotes is not affected. I tried with a regex, but I find problems when more than one quoted text is present in the string. Probably it’s not the right tool.
Do you have suggestions for a more straightforward way to achieve that?

Thanks!

So for example:

this is some "text" for you

becomes

THIS IS SOME "text" FOR YOU

?

Yes Kem exactly. But you can have more that one quoted text in the string (which is the problem with my regex…)

Try this (not tested):

Function UppercaseAroundQuotes (s As String) As String
  dim parts() as string = s.Split( """" )
  for i as integer = 0 to parts.Ubound step 2
    parts( i ) = parts( i ).Uppercase
  next
  return join( parts, """" )
End Function

thank you Kem.
the code looks so easy that I feel embarrassed for having opened the thread :slight_smile:
I will test it.

It works like a charm. Thanks again.

That’s great. But do you understand why it works? That’s often more important.

and embedded quote in quotes ?

this is some "t"foo"ext" for you

If the embedded quotes are doubled up, that code will still work:

this is some "t""foo""ext" for you

If they are escaped, something more (like a regex) to clean them up would be needed.

sure
change the problem definition :slight_smile:

Although its not really clear if my text shouldn’t result in

THIS IS SOME “t” FOO “ext” FOR YOU

or whether quoted text inside quoted text is permitted :slight_smile: