I wrote a simple code below which process string values “words”, if the word has a leading single quote (example: ‘em ) or a trailing one (example: tryin’) or both (example: ‘this’ ) then it removes them , if there are more than one instance of the mark it gets removed too. but if the quote mark is in the middle leave it alone, examples (America's, aren't, can't)
How do I achieve the same function differently and efficiently? And I don’t want to use a recursive procedure to do it.
Sub RemoveSurroundingSingleQuotes()
Dim arr(), wrd$
arr = Array("'wrd1'", "''wrd3''")
For i = 0 To UBound(arr)
wrd = arr(i)
Debug.Print "word before: " & wrd
RemoveLeft:
If Left(wrd, 1) = "'" Then wrd = Mid(wrd, 2)
'check the left side again
If Left(wrd, 1) = "'" Then GoTo RemoveLeft:
RemoveRight:
If Right(wrd, 1) = "'" Then wrd = Mid(wrd, 1, Len(wrd) - 1)
'check the Right side again
If Right(wrd, 1) = "'" Then GoTo RemoveRight:
Debug.Print "word after: " & wrd & vbCr & "--------------"
Next
End Sub