Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

How to? Parsing lines containing double quotes...

May
855
0
In a certain sense, I have a hard time believing I've never run into this before, and I also have a hard time believing that I even have to ask about it. But I've spent about 2 hours experimenting so far with no good results. So, to start, assume that I am reading data from a file whose lines take the following form:
Code:
Description for quoted field 1: "Quoted Field 1"   Description for quoted field 2: "Quoted Field 2" ...
What I want to do is quite trivial, at least in principle: Get the value of "Quoted Field 2".

I have done much experimentation without being able to use (at least reliably) the double-quote character as a field separator.

And if it's relevant, since there may be "unsafe" characters in the input data I'd like to use the "Safe" routines. But I will note that I haven't been able to get this to work consistently even if the "Safe" functions are not being used.
 
Code:
v:\> type desc.txt
Description for quoted field 1: "Quoted Field 1"
Description for quoted field 2: "Quoted Field 2"
 
v:\> do line in @desc.txt ( if %@index[%line,field 2] GE 0 echo %@word[5,%line] )
"Quoted Field 2"
 
Better ... refer to the last word in the line with
Code:
%@word[-0,%line])
 
v:\> do line in @desc.txt (if %@index[%line,field 2] GE 0 echo %@word[-0,%line])
"Quoted Field 2"
 
Thank you, Vince. I'm not completely clear what the difference between the @Word... and @Field... functions is in this context, but the @Word... functions did it perfectly. (BTW, I simplified things a little bit my example in that which quoted string (of several) I wanted depended on the (unquoted) word(s) that preceded and "described" the quoted string that followed, so which actual quoted string I wanted depended on the presence/absence of certain "key" words in the descriptions that preceded each quoted string.) Again, thank you, Vince.
 

Similar threads

Back
Top