Replace a letter in a word

D

Dinko Deranja

Suppose that you have a word e.g. "delicious" and an integer e.g. 5. How to
replace the letter at position 5 with letter in position 6 so that
"delicious" becomes "deliicous" ?
 
H

Helmut Weber

Hi Dinko,
Your result is not what your proposed algorithm should do.
Anyway:
 
D

Dinko Deranja

Thanks Helmut!

I modified slightly your code to do what I wanted. I wanted to replace char
5 with char 6 so that char 6 becomes char 5 and char 5 becomes char 6,
therefore, my result was fine. The code is:

Dim s As String
Dim s1 As String
s = "delicious"
s1 = Mid(s, 5, 1)
Mid(s, 5, 1) = Mid(s, 6, 1)
Mid(s, 6, 1) = s1
MsgBox s

and the result is "deliicous".
 

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

Top