[Date Prev][Date Next][Thread Prev][Thread Next]
[Author Index]
[Date Index]
[Thread Index]
[SQR-USERS Info]
[SQRUG Home Page]
neat way of parsing delimited list of strings...
- Subject: neat way of parsing delimited list of strings...
- From: Krisjanis Gale <Krisjanis.Gale@NY.FRB.ORG>
- Date: Tue, 6 Jul 1999 16:50:48 -0400
necessity is the mother invention.
working on an SQR that parses values
in a table and then generates an SQR that
acts on those values (don't ask! it's ugly what
i'm doing!) i ran into the problem of not having
an easy way to pull strings from a comma-delimited
string, one by one.
so i decided to "make it so."
here's a working SQR ditty that does just
what i thought it would.
it first counts the number of words in the string ($S),
then lists them invidually.
perhaps some of you will find this useful.
--
begin-program
let $S = 'this,is,a,comma,delimited,string'
let $S = $S || ',@'
let $tmp = $S
let $head = ''
let #wordcount = 0
while $tmp <> '@'
let #pos = instr($tmp,',',1)
let $tmp = substr($tmp,#pos+1,length($tmp)-#pos)
let #wordcount = #wordcount + 1
end-while
display #wordcount
let $tmp = $S
let $head = ''
while $tmp <> '@'
let #pos = instr($tmp,',',1)
let $head = substr($tmp,1,#pos - 1)
display $head
let $tmp = substr($tmp,#pos+1,length($S)-#pos)
end-while
end-program
--
(kris)janis p. gale
hrsd - federal reserve bank of new york
x8163