Loading ...
Sorry, an error occurred while loading the content.

Re: [Clip] spliting a big string into smaller variables

Expand Messages
  • Don - htmlfixit.com
    ... Hopefully this helps: ;*** Effort by Don Passenger ;*** don@htmlfixit.com ;*** discuss things live in chat at http://htmlfixit.com
    Message 1 of 2 , Jun 3, 2005
      dvdwriters12 wrote:
      > Suppose I have a string like the following:
      > title 1 some text title 2 other text 567034
      > How can I split this line upto into variables so I can use it in a
      > wizard ?
      > So:
      > title
      > 1
      > some
      > text
      > other
      > text
      > etc would appear.
      > We can assume that space is the field seperator.

      Hopefully this helps:
      ;*** Effort by Don Passenger
      ;*** don@...
      ;*** discuss things live in chat at http://htmlfixit.com
      ;I assume each line in the file is this 9 field data format:
      ;"title 1 some text title 2 other text 567034"

      ;start at the top (assuming whole file)
      ^!Jump Doc_Start

      ;set list delimiter to space and get array elements
      ^!SetListDelimiter " "

      ;get the row we are in
      ^!Set %row%="^$GetRow$"
      ;select the current line where cursor resides
      ;this will select the entire line from prior
      ;line feed to this one
      ^!Select Paragraph
      ;delimited array set by splitting line on spaces
      ^!SetArray %delimited_data%=^$GetSelection$
      ^!Set %indx%=1
      ;display each array element
      ^!Info Row is: ^%row% ^PElement ^%indx% is ^%delimited_data^%indx%%
      ;check if we have used all elements in current row
      ;compare current index number to number of elements
      ;in the array using delimited_data0 - which stores
      ;the number of elements in an array
      ^!If ^%indx% = ^%delimited_data0% Next_Line

      ^!Inc %indx%
      ^!Goto Loop_Display
      ;move to next line and then continue
      ;go to next line
      ^!Jump Select_End
      ;loop again if there are more rows
      ^!If ^%row% = ^$GetLinecount$ END ELSE Loop

      As usual I post my clip for later retrieval here:
      If you have an improvement or comment feel free to leave it over there
      for me.

      As I didn't exactly know what you wanted to do, I just took the fields
      to an info box. When you split on a delimiter, in this case a space,
      you get an array that contains the number of elements between the
      delimiters (in this case 9), plus a special 0 element which is the
      number of elements in the array. So you can address each element in the
      array using variablename1-9. If you don't know how many elements there
      might be, you check variable_name0 to find out.
    Your message has been successfully submitted and would be delivered to recipients shortly.