Removing Certain Items from a Key In an Array

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
mobert
Posts: 1
Joined: Sat Jan 03, 2015 10:39 pm

Removing Certain Items from a Key In an Array

Post by mobert » Sat Jan 03, 2015 10:43 pm

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!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10354
Joined: Wed May 06, 2009 2:28 pm

Re: Removing Certain Items from a Key In an Array

Post by dunbarx » Sun Jan 04, 2015 3:29 am

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

WaltBrown
Posts: 466
Joined: Mon May 11, 2009 9:12 pm

Re: Removing Certain Items from a Key In an Array

Post by WaltBrown » Sun Jan 04, 2015 3:10 pm

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 Brown
Omnis traductor traditor

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7394
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Removing Certain Items from a Key In an Array

Post by jacque » Sun Jan 04, 2015 10:19 pm

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

WaltBrown
Posts: 466
Joined: Mon May 11, 2009 9:12 pm

Re: Removing Certain Items from a Key In an Array

Post by WaltBrown » Mon Jan 05, 2015 4:45 am

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 Brown
Omnis traductor traditor

Post Reply