Page 1 of 1

Removing Certain Items from a Key In an Array

Posted: Sat Jan 03, 2015 10:43 pm
by mobert
Hi there,

I've recently been trying to count the amount of occurrences of a certain word in a book. However, LiveCode sees words joined with punctuation as a seperate word (e.g. "Wednesday,"). Is there anyway to filter out punctuation from a key in an array?

Many thanks!

Re: Removing Certain Items from a Key In an Array

Posted: Sun Jan 04, 2015 3:29 am
by dunbarx
Hi.

Do you mean that "Wednesday" and "Wednesday." (period) are different? If so, you will need to strip out such unwanted chars in the clear, and then reload back into an array.

This can be done with a repeat loop (fragment):

Code: Select all

put "abcdefghijklmnopqrstuvwxyz " into tValid --note inclusion of space
  repeat for each char tChar in yourText
     if tChar is in tValid then put tChar after temp
end repeat
Craig Newman

Re: Removing Certain Items from a Key In an Array

Posted: Sun Jan 04, 2015 3:10 pm
by WaltBrown
You may want to add caps to the solution offered by dunbarx (ABC...Zabc...z), or set caseSensitive to false, depending on how you are parsing the text. Also, check out regular expressions, especially if you need to differentiate hyphenated words (as in "mother-in-law") or contractions (as in "couldn't").
Walt

Re: Removing Certain Items from a Key In an Array

Posted: Sun Jan 04, 2015 10:19 pm
by jacque
Livecode version 7.x solves the punctuation problem with its "trueword" syntax, which returns only the word itself.

Re: Removing Certain Items from a Key In an Array

Posted: Mon Jan 05, 2015 4:45 am
by WaltBrown
trueWord is interesting. It recognizes an apostrophe as part of the word if there is a character following the apostrophe (as in "don't", which is a contraction of two words), but not a dash in any case (as in "mother-in-law", which is considered a single compound word), or an apostrophe followed by whitespace (as in "two weeks’ time"), which are all correct English usage (according to the OED).
Walt