Re: Splitting string on blanks in 4GL? (fwd)
Posted in 1995
Topics: Stored Procedures & SPL, Connectivity: ESQL/C, 4GL & Embedded SQL, Migration, Import/Export & Data Conversion, Platform-Specific Issues
An even better idea would be to use strtok(3c): 1) Write a C function called c_strtok() which basically is only an interface to the strtok(3C) call. 2) Now you can do like this: LET i=1 WHILE TRUE LET array[i] = c_strtok(str) IF (array[i] IS NULL) THEN EXIT WHILE END IF LET i = i + 1 IF (i > max_no_of_elements) THEN MESSAGE "Too many numbers ...." EXIT WHILE END IF END WHILE } } } shj@dknet.dk (Stig Jacobsen) writes: } } Howdy, } } } } I have a bunch of strings which looks like "500 328 729", that } } I'd like to seperate by whitespace and store into integer } } variables - basically like: } } } } define str char(100) } } define counts array[3] of integer } } } } select value from table into str } } let counts = split(str, ...) } } I know of no way the above syntax can work in 4GL, but why not simply: } let counts[1] = str[1,3] } let counts[2] = str[5,7] } let counts[3] = str[9,11] } if your input data is as well formed as you indicate. } } If not a for loop will do it with variables for str[p_start,p_end] } possibly with a whenever any error continue and test on status } or perhaps better, tests inside the for loop on every character } in str. } If you don't have millions of rows with these data even the for } loop approach should be reasonably fast. } } } } } ... after which counts[1] equals 500, counts[2] is 328, etc. } } } } What is the best way to do this? } } } } I thought of unloading str to an ascii file, using run to call } } a shell script or somesuch which would massage the unload file } } and produce a load file, which is the loaded into a suitable } } table created on the fly. Pretty horrible thought, yes? I haven't } } tried it yet, but I expect it to be a lot slower than my users } } would appreciate. } } } } Any input is welcomed. } } } } I'm running INFORMIX-4GL Version 4.11.UC2 on Solaris 2.3. } } Nils.Myklebust@ccmail.telemax.no } NM-data, Dalsbergstien 7, N-0170 Oslo, Norway } My opinions are those of my company } } -- -- Steinar Overbeck Cook Balder Programvare AS