Page 1 of 2
(Solved)How to use WordOffset to cut some text??
Posted: Thu May 27, 2021 3:23 pm
by Fasasoftware
Hi.. I need to delete e delimiter some text with wordoffset command....can you help me with some examples codes

please??'Thaks a lot ...Lestroso
Re: How to use WordOffset to cut some text??
Posted: Thu May 27, 2021 5:42 pm
by jmburnod
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
Re: How to use WordOffset to cut some text??
Posted: Thu May 27, 2021 6:33 pm
by dunbarx
Jean-Marc.
"Cut" ????
Craig
Re: How to use WordOffset to cut some text??
Posted: Thu May 27, 2021 6:41 pm
by Fasasoftware
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

Re: How to use WordOffset to cut some text??
Posted: Thu May 27, 2021 6:46 pm
by dunbarx
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
Re: How to use WordOffset to cut some text??
Posted: Thu May 27, 2021 6:48 pm
by jmburnod
Craig
"Cut" ????
Yes, I was surprised dictionary dont tell something about it
Lestroso
delOneWord need a param. Your pWord is empty
Jean-Marc
Re: How to use WordOffset to cut some text??
Posted: Thu May 27, 2021 6:51 pm
by dunbarx
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
Re: How to use WordOffset to cut some text??
Posted: Thu May 27, 2021 10:28 pm
by Fasasoftware
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

Re: How to use WordOffset to cut some text??
Posted: Fri May 28, 2021 1:11 am
by dunbarx
Jean-Marc.
It is not even a synonym of "delete".
Craig
Re: How to use WordOffset to cut some text??
Posted: Fri May 28, 2021 1:23 am
by dunbarx
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
Re: How to use WordOffset to cut some text??
Posted: Fri May 28, 2021 10:28 am
by bogs
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...

Re: How to use WordOffset to cut some text??
Posted: Fri May 28, 2021 12:27 pm
by Fasasoftware
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

Re: How to use WordOffset to cut some text??
Posted: Fri May 28, 2021 2:38 pm
by dunbarx
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
Re: How to use WordOffset to cut some text??
Posted: Fri May 28, 2021 2:42 pm
by dunbarx
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
Re: How to use WordOffset to cut some text??
Posted: Fri May 28, 2021 2:51 pm
by bogs
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 -
- You pick an event handler, or create a handler or function where you want the offset to be fired from.
- You put the {character, word, or multiple words} you want to be the offset into a variable.
- 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.
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.

- 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.