dbTalk Databases Forums  

4gl string parsing

comp.databases.informix comp.databases.informix


Discuss 4gl string parsing in the comp.databases.informix forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
monkeys paw
 
Posts: n/a

Default 4gl string parsing - 01-26-2011 , 12:01 PM






I need to parse a comma separated list of strings
in 4gl. If there is a number less than 290000 in the
list i need to return a true value, otherwise false.
I have something like:

let topix = "300000,310010,420011,650934,280000"
let top_loop = 0

while (top_loop < length(topic))
if (topix[top_loop, top_loop + 6] < 290000) then
return 1
end if
end while
return 0

Reply With Quote
  #2  
Old   
mpruet
 
Posts: n/a

Default Re: 4gl string parsing - 01-27-2011 , 06:25 PM






On Jan 26, 12:01*pm, monkeys paw <mon... (AT) joemoney (DOT) net> wrote:
Quote:
I need to parse a comma separated list of strings
in 4gl. If there is a number less than 290000 in the
list i need to return a true value, otherwise false.
I have something like:

let topix = "300000,310010,420011,650934,280000"
let top_loop = 0

* while (top_loop < length(topic))
* * * * if (topix[top_loop, top_loop + 6] < 290000) then
* * * * * * return 1
* * * * end if
* end while
* return 0
Converting my prior suggestion into a stored procedure...

This will let you do something like

execute function tst_string(100,"400,800,-1,50000");

--------------------------------------------------------------------------------------------

create function tst_string(maxnum int, str lvarchar) returns int
define tnum int;
define len int;
define sign int;
define sub int;
define tchar char(1);

let len = length(trim(str));
let sub = 1;

while sub < len
let tnum = 0;
let sign = 1;
let tchar = substring(str from sub for 1);
if tchar = '-' then
let sign = -1;
let sub = sub + 1;
let tchar = substring(str from sub for 1);
end if;

while ((sub < len) and (tchar != ','))
if (tchar != ',') then
let tnum = (tnum * 10) || tchar;
end if;
let sub = sub + 1;
let tchar = substring(str from sub for 1);
end while;
let sub = sub + 1;
if (tnum * sign) < maxnum then
return 1;
end if;
end while;

return 0;
end function;

Reply With Quote
  #3  
Old   
mpruet
 
Posts: n/a

Default Re: 4gl string parsing - 01-27-2011 , 06:33 PM



On Jan 26, 12:01*pm, monkeys paw <mon... (AT) joemoney (DOT) net> wrote:
Quote:
I need to parse a comma separated list of strings
in 4gl. If there is a number less than 290000 in the
list i need to return a true value, otherwise false.
I have something like:

let topix = "300000,310010,420011,650934,280000"
let top_loop = 0

* while (top_loop < length(topic))
* * * * if (topix[top_loop, top_loop + 6] < 290000) then
* * * * * * return 1
* * * * end if
* end while
* return 0
Opps - minor correction. the || should have been +

drop function tst_string(int, lvarchar);
create function tst_string(maxnum int, str lvarchar) returns int
define tnum int;
define len int;
define sign int;
define sub int;
define tchar char(1);

let len = length(trim(str));
let sub = 1;

while sub < len
let tnum = 0;
let sign = 1;
let tchar = substring(str from sub for 1);
if tchar = '-' then
let sign = -1;
let sub = sub + 1;
let tchar = substring(str from sub for 1);
end if;

while ((sub < len) and (tchar != ','))
if (tchar != ',') then
let tnum = (tnum * 10) + tchar;
end if;
let sub = sub + 1;
let tchar = substring(str from sub for 1);
end while;
let sub = sub + 1;
if (tnum * sign) < maxnum then
return 1;
end if;
end while;

return 0;
end function;

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.