Re: help with storing user input
- Posted by Jason Dube <dubetyrant at hotmail.com> May 15, 2003
- 419 views
wow! Thank you! Definately gonna look at this close. I'd like to try to use it in my program, if I have some questions about it, is it ok if I ask? >From: Derek Parnell <ddparnell at bigpond.com> >Subject: Re: help with storing user input > > >----- Original Message ----- >From: "Jason Dube" <dubetyrant at hotmail.com> >To: "EUforum" <EUforum at topica.com> >Subject: help with storing user input > > > > Hello, > > What would be an efficient way of seperating words in a user inputted >sentence? For example to break apart the words in a sentence. Im >specifically trying to develop a GOOD algoritm to seperate words from user >inputed sentence and store them as individual sequences.Like: > > user input:"mary had a little lamb" > > results:sequence 1st_sentence={"mary","had","a","little","lamb") > > Im having difficulties skipping whitespaces and converting to string > > > > how would euphoria do this:? >Here are a couple of routines that I use... > > >-- pText is returned as a sequence of 'words'. >-- Each word is delimited by a set of one or more Delimiters > > > sequence lTokens > integer lStartQuote, lEndQuote > integer lTextLength > integer lStart > integer lPos > > -- Validate whitespace parameter > if atom(pWhiteSpace) then > if pWhiteSpace = 0 then > pWhiteSpace = ' ' & 8 & 9 & 10 & 11 & 12 & 13 > else > pWhiteSpace = {pWhiteSpace} > end if > end if > > -- Validate non-word parameter > if atom(pNonword) then > if pNonword = 0 then > pNonword = "`~!@#$%^&*()_-+={[}]|\\:;\"'<,>.?/" > else > pNonword = {pNonword} > end if > end if > > -- Validate quote marks parameter > if sequence(pQuotes) then > if length(pQuotes) = 0 then > pQuotes = {{},{},{},{},{}} > elsif (length(pQuotes) != 5 > or > atom(pQuotes[1]) > or > atom(pQuotes[2]) > or > atom(pQuotes[3]) > or > length(pQuotes[1]) != length(pQuotes[2]) > or > atom(pQuotes[4]) > or > atom(pQuotes[5]) > or > length(pQuotes[4]) != length(pQuotes[5]) > ) > then > pQuotes = 0 > end if > end if > > if atom(pQuotes) then > if pQuotes = 0 then > pQuotes = {"\"'`", "\"'`", "\\~","",""} > else > pQuotes = {{pQuotes}, {pQuotes},{},{},{}} > end if > end if > > -- Initialize > lTokens = {} > lStart = 0 > lStartQuote = 0 > lEndQuote = 0 > for i = 1 to length(pText) do > if lStartQuote != 0 then > if pText[i] = lEndQuote then > if find(pText[i - 1], pQuotes[3]) then > if i > 2 and find(pText[i - 2], pQuotes[3]) then > lTokens = append(lTokens, pText[lStart .. i - 1]) > lStart = 0 <snip> > >