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!
Removing Certain Items from a Key In an Array
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Re: Removing Certain Items from a Key In an Array
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):
Craig Newman
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
Re: Removing Certain Items from a Key In an Array
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
Walt
Walt Brown
Omnis traductor traditor
Omnis traductor traditor
Re: Removing Certain Items from a Key In an Array
Livecode version 7.x solves the punctuation problem with its "trueword" syntax, which returns only the word itself.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Removing Certain Items from a Key In an Array
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
Walt
Walt Brown
Omnis traductor traditor
Omnis traductor traditor