Visual Basic help needed to use Replace functionality

yugpatel

Senior member
Feb 28, 2001
506
0
76
I am trying to parse the following lines of data:
Slot : "6" "Feeder" : "12mm/8mm Tape" "Component ID" : "WLK0148" "Feeder Slot" : "6" "Rotation" : "0.000"
Slot : "15" "Feeder" : "Belt Reject" "Component ID" : "WLK0148" "Feeder Slot" : "15" "Rotation" : "0.000"
Slot : "8" "Feeder" : "12mm/8mm Tape" "Component ID" : "400010-001" "Feeder Slot" : "8" "Rotation" : "0.000"
............
............
............ so forth and so on......

where slot, feeder, Component ID, Feeder Slot and Rotation are datafields and value next to each of them is value corresponding to each field.
I want to parse these lines so that I can get the following output:
slot[tab] Feeder[TAB] Component ID[TAB] Feeder Slot[TAB]Rotation
6[TAB]12mm/8mm Tape[TAB]................

How can I do this in VB?

I tried to use Replace function with "blank" (quotes inclusive) with |(pipe) as search string as follow but I got syntax error:
Replace(sourceString, " '"' '"' ", "|")
What is the correct syntax?
TIA....
 

igowerf

Diamond Member
Jun 27, 2000
7,697
1
76
You'd probably have go escape the quotes. You can't just quote some quotes. How is VB supposed to know where the quoted string ends?

Replace(sourceString, " '\"' '\"' ", "|")

Mabe escape the single quotes too?

Replace(sourceString, " \'\"\' \'\"\' ", "|")

If that doesn't work, you can use ascii values and the Chr() function. I haven't done VB in a while so I'm a little fuzzy on it.

Also, I thought you were trying to make it tab delimited. What's with searching for quotes and pipes and whatnot?
 

noxxic

Senior member
Dec 21, 2000
254
0
0
A single quote is """" (that's " 4x), and a tab is vbTab or chr(9).

If you are using VB.NET, I think it now has a regex library and you may want to try that also.
 

yugpatel

Senior member
Feb 28, 2001
506
0
76
Originally posted by: igowerf
You'd probably have go escape the quotes. You can't just quote some quotes. How is VB supposed to know where the quoted string ends?

Replace(sourceString, " '\"' '\"' ", "|")

Mabe escape the single quotes too?

Replace(sourceString, " \'\"\' \'\"\' ", "|")

If that doesn't work, you can use ascii values and the Chr() function. I haven't done VB in a while so I'm a little fuzzy on it.

Also, I thought you were trying to make it tab delimited. What's with searching for quotes and pipes and whatnot?

A friend of mine suggested using escape character but I don't know how exactly I would to that. I tried your Replace example but got compilation error. Speaking of ascii and char(0, can you guide me how to do that?
Thanks for your help.

 

igowerf

Diamond Member
Jun 27, 2000
7,697
1
76
Google for an ascii table so you can figure out which numbers mean which characters. For example, chr(32) is a space.

Also, I believe I was wrong about escaping with a \, as noxxic pointed out. I think in VB, you put quotes within quotes by using two double quotes.

" ""This is a sentence surrounded by quotes."" "

To add a tab, just go "my string" & vbTab.

 

BZ

Member
Jan 9, 2003
160
0
0
resultString = Replace(sourceString, """ """, Chr(9))
that's 3 quotes a space and 3 more quotes. chr(9) is tab but you can also use vbtab. I believe quote is 34 if the above doesn't work
 

yugpatel

Senior member
Feb 28, 2001
506
0
76
Originally posted by: BZ
resultString = Replace(sourceString, """ """, Chr(9))
that's 3 quotes a space and 3 more quotes. chr(9) is tab but you can also use vbtab. I believe quote is 34 if the above doesn't work

Thanks to all of you. It works...with resultString = Replace(sourceString, """ """, Chr(9)).