4 Replies Latest reply on Apr 27, 2007 12:03 PM by Newsgroup_User

    multiple characters in itemDelimiter

    PpHammer
      Hi guys!

      This might be a stupid question and I only need confirmation, I think, with the following. I couldn't find anything conclusive about it. It's ONLY possible to use a single character in the ItemDelimiter? I.e. "\" or "-". We've been using other programs which can delimit on strings with multiple characters. There are moments when doing lingo that this could be a life saver.
      So to cut things short: only one character? Or am I missing something?

      Greetz,
      Pieter
        • 1. Re: multiple characters in itemDelimiter
          Level 7
          If you are using MX2004 you can use JavaScript functions like
          string.split() and/or full-blown regular expressions
          Here's an example from Direct-L:
          //
          function javascript_split(inStr, delStr) {
          var myArr = inStr.split(delStr);
          var myList = list();
          for(var i = 0; i < myArr.length ; i++) {
          myList.append(myArr );
          }
          return myList;
          }

          trace javascript_split("as er rt tyty", "r r")
          -- ["as e", "t tyty"]

          And here's a Lingo implementation of the same idea:
          --
          ------------------------------------------
          on split arg1,arg2,arg3

          -- arg1,arg2 are source & delimiter
          -- arg3 is optional max number of items (remaining source is dumped
          into last item)

          -- determine which of first two args is delimiter by which is
          shortest string
          if arg1.length < arg2.length then
          tDelimiter = arg1
          tString = arg2
          else
          tDelimiter = arg2
          tString = arg1
          end if

          if (not(tString contains tDelimiter)) or tString="" then
          return [tString]
          end if

          if voidp(arg3) then
          maxItems = 0
          else
          maxItems = arg3
          end if

          -- split a string into an array delimited by tDelimiter
          tArray = []
          nextDelimiterPos = 0
          repeat while true
          if tDelimiter<>"" then
          nextDelimiterPos = offset(tDelimiter,tString)
          else
          nextDelimiterPos = 2*(tString.length>1)
          end if
          if nextDelimiterPos=0 then
          tArray.add(tString)
          tString = ""
          exit repeat
          else
          if maxItems>0 and (tArray.count = maxItems-1) then
          -- reached max items : dump the rest of the string into last item
          tArray.add(tString)
          tString = ""
          exit repeat
          end if
          if nextDelimiterPos>1 then
          tArray.add(tString.char[1..nextDelimiterPos-1])
          else
          tArray.add("")
          end if
          tString =
          tString.char[(nextDelimiterPos+tDelimiter.length)..tString.length]
          end if
          end repeat
          return tArray
          end
          ------------------------------------------------

          Or you could try the free PRegEx xtra which also has a split() method
          < http://www.openxtras.org/pregex/>
          • 2. Re: multiple characters in itemDelimiter
            PpHammer Level 1
            Thanks for your reply!
            Unfortenately we don't use javaScript, but there are some nice pointers in it. Will try it and possibly make an ultimate delimit script in ordinary lingo to end this once and for all ;)
            • 3. Re: multiple characters in itemDelimiter
              Level 7
              PpHammer wrote:
              > Thanks for your reply!
              > Unfortenately we don't use javaScript, but there are some nice
              > pointers in it. Will try it and possibly make an ultimate delimit
              > script in ordinary lingo to end this once and for all ;)

              I recommend using the PRegEx xtra as Sean suggested.

              Sean wrote:
              > Or you could try the free PRegEx xtra which also has a split() method
              > < http://www.openxtras.org/pregex/>

              Andrew


              • 4. Re: multiple characters in itemDelimiter
                Level 7
                > Will try it and possibly make an ultimate delimit script in ordinary lingo to
                > end this once and for all ;)

                I already posted one in my previous reply. However, for longer strings
                the PRegEx xtra will prove *much* faster.