Automate insert text

  • Thread starter Thread starter Diogo
  • Start date Start date
D

Diogo

I've a unic string of 2000 characters, how can I automate the procedure of
inserting a "\" every three characters?

string as is =
Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3Ab4Ab5Ab6Ab7Ab8Ab9Ac0Ac1Ac2Ac3Ac4Ac5Ac6Ac7Ac8Ac9Ad0Ad1Ad2Ad3Ad4Ad5Ad6Ad7Ad8Ad9Ae0Ae1Ae2Ae3

string to be = Aa0\Aa1\Aa2\Aa3\Aa4\Aa5\Aa6\Aa7\.....
 
Diogo said:
I've a unic string of 2000 characters, how can I automate the procedure of
inserting a "\" every three characters?

string as is =
Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3Ab4Ab5Ab6Ab7Ab8Ab9Ac0Ac1Ac2Ac3Ac4Ac5Ac6Ac7Ac8Ac9Ad0Ad1Ad2Ad3Ad4Ad5Ad6Ad7Ad8Ad9Ae0Ae1Ae2Ae3

string to be = Aa0\Aa1\Aa2\Aa3\Aa4\Aa5\Aa6\Aa7\.....


Public Sub InsertSlashes()

Const strcTest As String =
"Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3Ab4Ab5Ab6Ab7Ab8Ab9Ac0Ac1Ac2Ac3Ac4Ac5Ac6Ac7Ac8Ac9Ad0Ad1Ad2Ad3Ad4Ad5Ad6Ad7Ad8Ad9Ae0Ae1Ae2Ae3"

Dim strWork As String
Dim lngLoop As Long

For lngLoop = 1 To Len(strcTest) Step 3
strWork = strWork & Mid$(strcTest, lngLoop, 3) & "/"
Next lngLoop
strWork = Left$(strWork, Len(strWork) - 1)

Debug.Print strWork

End Sub

Result in the Immediate window ...

insertslashes
Aa0/Aa1/Aa2/Aa3/Aa4/Aa5/Aa6/Aa7/Aa8/Aa9/Ab0/Ab1/Ab2/Ab3/Ab4/Ab5/Ab6/Ab7/Ab8/Ab9/Ac0/Ac1/Ac2/Ac3/Ac4/Ac5/Ac6/Ac7/Ac8/Ac9/Ad0/Ad1/Ad2/Ad3/Ad4/Ad5/Ad6/Ad7/Ad8/Ad9/Ae0/Ae1/Ae2/Ae3
 
Back
Top