Finding words whilst ignoring apostrophes

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
PoLyGLoT
Posts: 105
Joined: Sat Jan 14, 2012 12:37 am

Finding words whilst ignoring apostrophes

Post by PoLyGLoT » Thu Feb 23, 2017 2:58 pm

Hello,

Is there any way to search for items and ignore apostrophes?

I'm attempting to do this:

Code: Select all

if "USA"  is among the items of line z of goodDemo then
add 1 to numUSA
end if
Sometimes, USA will be written as "USA" in goodDemo, and it will not detect it.

Any workaround here?
Thank you!

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Finding words whilst ignoring apostrophes

Post by Klaus » Thu Feb 23, 2017 3:34 pm

Hi PoLyGLoT,

use "truewords" instead of "items"!
Will work with USA, "USA" and 'USA', and other countries, too, of course! 8)

Code: Select all

...
if "USA"  is among the truewords of line z of goodDemo then
  add 1 to numUSA
end if
...
Tested and works! :D


Best

Klaus

Lagi Pittas
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 366
Joined: Mon Jun 10, 2013 1:32 pm

Re: Finding words whilst ignoring apostrophes

Post by Lagi Pittas » Thu Feb 23, 2017 3:39 pm

Hi

I'm sure there is a more elegant way and shorter but this is clear and easy to change. It would only matter speed wise if you had (many?) thousands of lines I'm sure.

Code: Select all

on mouseup
  repeat with lnX = 1 to the number of lines in field "lstGoodDemo"
      put ReplaceText(line lnX of field  "lstGoodDemo",quote,empty) into lcText
      if "USA"  is among the items of lcText then
         add 1 to lnNum
      end if
   end repeat
   
   put lnNum
end mouseup 

PoLyGLoT
Posts: 105
Joined: Sat Jan 14, 2012 12:37 am

Re: Finding words whilst ignoring apostrophes

Post by PoLyGLoT » Thu Feb 23, 2017 3:50 pm

Thank you both for your responses.

The "truewords" solution works, but has 1 downside (at least for my data): It only seems to work on single words. For instance, this does not catch "United States of America":

Code: Select all

else if "United States of America" is among the truewords of line z of goodDemo then
add 1 to numUSA
However, this does work:

Code: Select all

put ReplaceText(line z of goodDemo,quote,empty) into line z of goodDemo
else if "United States of America" is among the items of line z of goodDemo then
add 1 to numUSA
Perhaps truewords only works on single words? Not sure, but I appreciate both your responses and glad I figured out a way to make it work! 8)

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Finding words whilst ignoring apostrophes

Post by Klaus » Thu Feb 23, 2017 3:57 pm

Yes, as its name suggests, it will only work with WORDS.
And that was your original question. :wink:

Maybe you better use "contains" or "offset" or something like that?

PoLyGLoT
Posts: 105
Joined: Sat Jan 14, 2012 12:37 am

Re: Finding words whilst ignoring apostrophes

Post by PoLyGLoT » Thu Feb 23, 2017 4:13 pm

Klaus wrote:Yes, as its name suggests, it will only work with WORDS.
And that was your original question. :wink:

Maybe you better use "contains" or "offset" or something like that?
Yes! I had assumed the solution might apply to everything. :P

Given that I will probably never have thousands and thousands of lines, I can use the replaceText solution that was offered. :mrgreen:

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Finding words whilst ignoring apostrophes

Post by Thierry » Thu Feb 23, 2017 5:05 pm

PoLyGLoT wrote:
Yes! I had assumed the solution might apply to everything. :P
Given that I will probably never have thousands and thousands of lines,
I can use the replaceText solution that was offered. :mrgreen:
What about this one?

Code: Select all

  put "\b" & "USA" & "\b" into searchForUSA
  repeat for each line T in field 1
      if matchChunk( T, searchForUSA) then add 1 to n
   end repeat
Fast and ready for long text...
Could be improved a bit but as I don't know your data, I assume it's enough.

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

Post Reply