Parsing ""D""? 
Author Message
 Parsing ""D""?

I need to parse a record, where a empty record
looks like this:

"" "" ""

But the problem I'm having is there can be quotes inside the quotes,
like this:

"IC1"  ""D" Flip-Flop"  "74HC74"
"IC2"  " "D" Flip-Flop  " "4013"

How do I break that in to the three fields?

--
For information on any of the following check out my WEB site at:
                    http://www.*-*-*.com/
Chemical Free Air Conditioning/No CFC's, Chronic Pain Relief, Echofone,
Electromedicine, Electronics, Explore!, Free Energy, Full Disclosure,
KeelyNet, Matric Limited, Neurophone, Oil City PA, Philadelphia Experiment.
                          http://www.*-*-*.com/



Tue, 21 May 2002 03:00:00 GMT  
 Parsing ""D""?

Quote:

> I need to parse a record, where a empty record
> looks like this:

> "" "" ""

> But the problem I'm having is there can be quotes inside the quotes,
> like this:

> "IC1"  ""D" Flip-Flop"  "74HC74"
> "IC2"  " "D" Flip-Flop  " "4013"

> How do I break that in to the three fields?

Oh oh, rather broken design (but that's not yourfault, of course).
If the first and third column never have whitespace, you could try
extracting these columns first, and leave the second column for further
treatment:

FS = " "
Field[1] = $1
Field[3] = $NF  # the last field
$1 = $NF = ""
Field[2] = $0

# now discard leading and trailing blanks and doublequotes:
for(i in Field)
{
  gsub(/^[\" ]+/,"",Field[i])
  gsub(/[\" ]+$/,"",Field[i])

Quote:
}

If the first and the third column might have embedded whitespace, but
never embedded doublequotes, I would try:

FS = "\""
Field[1] = $2   # $1 is before the first doublequote now
Field[3] = $(NF-1)
$2 = $(NF-1) = ""

# and now again:
Field[2] = $0

# now discard leading and trailing blanks and doublequotes:
for(i in Field)
{
  gsub(/^[\" ]+/,"",Field[i])
  gsub(/[\" ]+$/,"",Field[i])

Quote:
}

Regards...
                Michael


Tue, 21 May 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. string.join(["Tk 4.2p2", "Python 1.4", "Win32", "free"], "for")

2. BEGIN{want[]={"s1o", "s2o", "s2q", "s3q"}

3. "Fifth", "Forth", zai nar?

4. Ruby "finalize", "__del__"

5. beginners "let"/"random" question

6. ANNOUNCE: new "plus"- and "dash"-patches available for Tcl7.5a2/Tk4.1a2

7. Looking for "stdin", "stdout"

8. sysdsn and "migrat" ds (os390)

9. Match "ab" in "abc", but not in "abd"

10. replace string AFTER "size","initial", "next"

11. Hi, this code: text0 = "One $BLAH Three" text1 = "One @BLAH Three" text0.sub!("$BLAH", "Two") text1.sub!("@BLAH", "Two") print text0,"\n" print text1,"\n" produces thiHi, this code: text0 = "One $BLAH Three" text1 = "One @BLAH Three" text0.sub!("$BLAH", "T

12. Lack of "D Tests", "E Tests", and "L Tests" for Generics

 

 
Powered by phpBB® Forum Software