w0051977
w0051977

Reputation: 15817

Add character to string using VB6

Say I have an address like this:

Dim address as string
address= "1 The Street, London, LN11SD"

I want to add a space before the last three characters so the address looks like this (notice the space in the post code):

1 The Street, London, LN1 1SD

How can I do this? I have spent the last hour Googling this simple problem and I have found lots of examples of how to do this in VB.NET using string.Insert. However, I cannot find any examples that talk about VB6 and hence the reason for the question.

Upvotes: 0

Views: 2068

Answers (2)

Tendai Mare
Tendai Mare

Reputation: 31

Step 1 - You have to take all the address variable and remove the last 3 characters using the Mid function
Step 2 - add the space
Step 3 - use the right function to get the last 3 characters

Dim address As String
address = "1 The Street, London, LN11SD"

address = Mid(address, 1, Len(address) - 3) & " " & Right(address, 3)

Upvotes: 2

tcarvin
tcarvin

Reputation: 10855

Simplistically, you can do this:

Dim address as string
address = "1 The Street, London, LN11SD"

address = Left$(address, 25) & " " & Right$(address, 3)

That being said, I think you'd need a lot more logic to detect exactly where there was a missing space in a large set of addresses.

Upvotes: 1

Related Questions