(Solved)How to use WordOffset to cut some text??

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

Fasasoftware
Posts: 203
Joined: Mon Oct 31, 2011 9:36 pm
Location: Italy
Contact:

(Solved)How to use WordOffset to cut some text??

Post by Fasasoftware » Thu May 27, 2021 3:23 pm

Hi.. I need to delete e delimiter some text with wordoffset command....can you help me with some examples codes :oops: please??'Thaks a lot ...Lestroso
Last edited by Fasasoftware on Fri May 28, 2021 3:48 pm, edited 1 time in total.

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: How to use WordOffset to cut some text??

Post by jmburnod » Thu May 27, 2021 5:42 pm

Hi,
What about this ?

Code: Select all

on delOneWord pWord
   put wordoffset(pWord,fld 1) into tNumW
   delete word tNumW of fld 1 -- works !
  -- cut word tNumW of fld 1 -- also works ! 
end delOneWord
Best
Jean-Marc
https://alternatic.ch

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9578
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How to use WordOffset to cut some text??

Post by dunbarx » Thu May 27, 2021 6:33 pm

Jean-Marc.

"Cut" ????

Craig

Fasasoftware
Posts: 203
Joined: Mon Oct 31, 2011 9:36 pm
Location: Italy
Contact:

Re: How to use WordOffset to cut some text??

Post by Fasasoftware » Thu May 27, 2021 6:41 pm

Code: Select all

on mouseUp 
   delOneWord 
end mouseUp

on delOneWord pWord
   put wordoffset(pWord,fld "RESULT") into tNumW
   delete word tNumW of fld "RESULT" -- works !
   -- cut word tNumW of fld 1 -- also works ! 
end delOneWord
Nothing works here...can you help please??? Best regards, Lestroso :oops:

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9578
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How to use WordOffset to cut some text??

Post by dunbarx » Thu May 27, 2021 6:46 pm

Lestroso.

What Jean-Marc said, but a simple example of the wordOffset function will only find the first word in some text. There are ways to find the others, but what do you need for your stack?

Also, did you really mean "delimiter"? Or just a word in some text? A delimiter might allow other methods to work.

Craig

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: How to use WordOffset to cut some text??

Post by jmburnod » Thu May 27, 2021 6:48 pm

Craig
"Cut" ????
Yes, I was surprised dictionary dont tell something about it

Lestroso
delOneWord need a param. Your pWord is empty

Jean-Marc
https://alternatic.ch

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9578
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How to use WordOffset to cut some text??

Post by dunbarx » Thu May 27, 2021 6:51 pm

Hi.

If you read the code, you will see that the variable "pWord" is never defined. Jean-Marc was giving an example of how the function works. He does not know which word anyone is actually interested in.

You can make this yours by adding:

Code: Select all

on mouseUp 
   delOneWord "yourWordHere"
end mouseUp
But why use two handlers when one will do?

Craig

Fasasoftware
Posts: 203
Joined: Mon Oct 31, 2011 9:36 pm
Location: Italy
Contact:

Re: How to use WordOffset to cut some text??

Post by Fasasoftware » Thu May 27, 2021 10:28 pm

First of all, i want to thank you every body for yours efforts..
Ok.. in simple words...

I need to delete in a field.. from the word 1 to a word defined by me in a variable...and cut it..simple this... but i don't remember if i should use wordoffset or not...Thanks a lot again..Lestroso :oops:

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9578
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How to use WordOffset to cut some text??

Post by dunbarx » Fri May 28, 2021 1:11 am

Jean-Marc.

It is not even a synonym of "delete".

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9578
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How to use WordOffset to cut some text??

Post by dunbarx » Fri May 28, 2021 1:23 am

Fasasoftware

Check out "wordOffset" in the dictionary. You will find that you can set "words to skip", so as not to be limited to only the first occurrence. So if you wanted to delete the fourth occurrence, that extra parameter gives you the tools to do so.

Craig

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: How to use WordOffset to cut some text??

Post by bogs » Fri May 28, 2021 10:28 am

dunbarx wrote:
Fri May 28, 2021 1:11 am
Jean-Marc.
It is not even a synonym of "delete".
Um, maybe someone 'cut' this entry from the current dictionary...

Image
Image

Fasasoftware
Posts: 203
Joined: Mon Oct 31, 2011 9:36 pm
Location: Italy
Contact:

Re: How to use WordOffset to cut some text??

Post by Fasasoftware » Fri May 28, 2021 12:27 pm

Dear friends,

I need to delete in a field.. from the word 1 to a word defined by me in a variable...Can you help me with some fresh code???.Thanks a lot again..Lestroso :oops: :oops: :oops:

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9578
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How to use WordOffset to cut some text??

Post by dunbarx » Fri May 28, 2021 2:38 pm

Hi.

Put some text into field 1. In a button script:

Code: Select all

on mouseUp
   ask "Delete up to which word?"
   delete word 1 to wordOffset(it,fld 1) of fld 1
end mouseUp
Enter the word you want to delete up to.

More importantly, do you see how this works? Write back if you do not see it clearly, please.

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9578
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How to use WordOffset to cut some text??

Post by dunbarx » Fri May 28, 2021 2:42 pm

Bogs.

I know you still work in v.1.0.

Is "cut" in your working dictionary? If so, just a simple omission. But either one of "cut" or "delete" ought to me a synonym of the other. "Delete" was a Hypercard native word, so I think "cut" should not have its own place, unless it does other things that delete does not.

Craig

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: How to use WordOffset to cut some text??

Post by bogs » Fri May 28, 2021 2:51 pm

Lestroso, I'm not sure exactly where the previous examples are failing to be understood, but no matter which version of offset you use, the usage basically goes like this -
  1. You pick an event handler, or create a handler or function where you want the offset to be fired from.
  2. You put the {character, word, or multiple words} you want to be the offset into a variable.
  3. You then setup the offset statement.
It really isn't any more complicated than that.

The attached stack is commented and uses lineOffset to pick lines from the source of the website you linked to in another thread as the base example.
offSet_Demo.livecode.zip
OffsetDemo.
(199.99 KiB) Downloaded 132 times
You can either type or copy / paste a word (or words) from the source into the word 1 and 2 fields. When you hit "cmdDel" you will be prompted whether or not to delete the lines shown (line numbers in the "Start" and "End" line fields, the actual text shown on the right). If you press "Yes", well, I hope you get the idea.
aPic_lineOffset.png
A thousand words?
@Craig -
I was actually setting up this example in 6.7.9 (*which I know is one of your absolute FAV versions !!*) when I cracked the dictionary and looked up cut for you ;)

I do not think cut should be a direct synonym of delete, when you delete something, you are just getting rid of it, when you cut something, you have the option of putting it either back, or someplace else.
Image

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”