Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

123 convert into '123' 2

Status
Not open for further replies.

Zargo

Programmer
Mar 21, 2005
109
Hi,

I'm using 2 pages of codes to convert a string with delimiters(,) into another string...

How can we smartly convert 123,abcd,987 into '123','456','abcd','987'

I'm using arrays to put the values into the array and cut the string...maybe there is a better way...

A star for the smartes part of code...

Thanks in advance..
 
This has been covered many times - search for Split will give you what you need.

 
Code:
MsgBox "'" & Replace("123,abcd,987", ",", "','") & "'"

------------------------------------------
The faulty interface lies between the chair and the keyboard.
 
123,abcd,987 into '123','456','abcd','987'

Did I miss the '456' part?

------------------------------------------
The faulty interface lies between the chair and the keyboard.
 
Sorry, yes i have missed the 4,5,6 part....

I'm going to test the replys...
 
Wow VbSun Thanks....(a star!!!). How to do this with a split function?
 
Code:
Dim arrTmp() As String
Dim strOutPut As String
Dim strOriginal As String
Dim i As Integer

strOriginal = "123,abcd,987"

arrTmp = Split(strOriginal, ",")

For i = 0 To UBound(arrTmp)
    arrTmp(i) = "'" & arrTmp(i) & "'"
Next

For i = 0 To UBound(arrTmp)
    strOutPut = strOutPut & arrTmp(i) & ","
Next

strOutPut = Left(strOutPut, Len(strOutPut) - 1)
MsgBox strOutPut

------------------------------------------
The faulty interface lies between the chair and the keyboard.
 
Here is another example of using the split method.

Code:
Dim strOriginal As String
    
strOriginal = "123,abcd,987"
MsgBox "'" & Join(Split(strOriginal, ","), "','") & "'"

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Thanks Gmmastros also a good line of code

THANKS!!!!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top