Separating characters within a field

AlexD

Registered User.
Local time
Today, 19:40
Joined
Sep 20, 2002
Messages
35
Hi,

Simple question really (if you know your VBA)...

Have a field which contains records of strings of alphabetic characters i.e.

ADGHJLP
BCEFHIJKLMOPST
etc

Need to be able to separate these characters with a '/' so that the field reads

A/D/G/H/J/L/P
B/C/E/F/H/I/J/K/L/M/O/P/S/T

etc

I know it'll be a For..Next loop of some kind but can't seem to get the syntax correct.

Any help appreciated.

cheers,

Alex
 
There's almost certainly a neater way of doing this, but the following works.

Dim str_Start as String
Dim str_Result as String
Dim li_Start_Len as Integer
Dim li_Len as Integer

Str_Start = “ABCDEFG”
Str_Start_Len = Len(Str_Start)
Li_Len = Str_Start_Len

Do While li_Len >0

Str_Result = Left(Str_Start,1)
Str_Result = Str_Result & “/”
Str_Start = Right(Str_Start, Str_Start_Len – 1)
Li_Len = Li_Len - 1

Loop
 
Alternately
Code:
Function FunPadString(strIn)
Dim i As Integer
FunPadString = Left(strIn, 1)
For i = 2 To Len(strIn)
    FunPadString = FunPadString & "/" & Mid(strIn, i, 1)
Next i
End Function

Sub testPad()
Debug.Print FunPadString("BCEFHIJKLMOPST")
End Sub

HTH

Peter
 
Bat17 said:
Alternately
Code:
Function FunPadString(strIn)
Dim i As Integer
FunPadString = Left(strIn, 1)
For i = 2 To Len(strIn)
    FunPadString = FunPadString & "/" & Mid(strIn, i, 1)
Next i
End Function

Sub testPad()
Debug.Print FunPadString("BCEFHIJKLMOPST")
End Sub

HTH

Peter

Thanks Peter,

Seems to have done the trick!

cheers...Alex
 

Users who are viewing this thread

Back
Top Bottom