Re: Exploding column-data question
Posted in 1994
CAVILA@zycon.com writes: > I have a varchar column with data that looks like this example: > my_list A/BC/D/EFG/H/ > The "/" character can be replaced by any printable character, it is only > there to serve as a delimiter. > I'd like to assign this to a record variable and then use a display array > to have my form end up looking like this: > [ A] > [ BC] > [ D] > [EFG] > [ H] > My question is: can this be done easily using Informix 4GL? Can someone > please post a way to parse through the list and address each of the data > elements? Also, would there be a way to address one specific piece of > data, without having to look at each character? (ie: my_list(3) = "D") > Thanks in advance for your help, it'll be appreciated! Deja Vu. A very similar question was posted a couple weeks ago, or maybe my answer didn't get out then: DEFINE len SMALLINT # LENGTH indicator DEFINE st SMALLINT # start of each subscreen DEFINE fn SMALLINT # finish of each subscreen DEFINE x SMALLINT # counter DEFINE arr SMALLINT # array counter DEFINE la_record ARRAY[100] OF RECORD list CHAR(3) END RECORD LET arr = 0 LET st = 1 LET fn = 0 LET len = LENGTH(my_list) FOR x = 1 TO len IF my_list[x] = "/" THEN # we're on a delimiter # set up the finish point to the char before the delimiter LET fn = x - 1 LET arr = arr + 1 IF arr > 100 THEN ERROR "Too many delimited fields" EXIT FOR END IF IF fn > 0 AND st <= fn THEN LET la_record[arr].list = my_list[st,fn] ELSE # either we found a delimiter at the beginning of the string # or there were two or more delimiters in a row. Assume a null row LET la_record[arr].list = NULL END IF # set the starting point of the next string to one after the delimiter LET st = x + 1 END IF END FOR IF st < len THEN # there was a field at the end of the string, which did not end with # a delimiter, so fill it in LET arr = arr + 1 IF arr > 100 THEN ERROR "Too many delimited fields" ELSE LET la_record[arr].list = my_list[st,len] END IF END IF IF arr > 100 THEN LET arr = 100 END IF CALL set_count(arr) DISPLAY ARRAY ... ============================================================ Dennis J. Pimple Informix Software Inc Senior Consultant Denver Colorado USA dennisp@informix.com Voice:303-850-0210 Fax:303-779-4025