Delet all characters after word x
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Delet all characters after word x
Hi,
Is there an easy way to delete all characters (including tab,return etc) after a certain word in a line of text.
The amount and content of characters either side of word 6 varies so applying a fixed delete (char 5 to 7 etc) won't work..
Is there an easy way to delete all characters (including tab,return etc) after a certain word in a line of text.
The amount and content of characters either side of word 6 varies so applying a fixed delete (char 5 to 7 etc) won't work..
Re: Delet all characters after word x
Use matchchunk to find the match. (you might look at wholematches in the dictionary too)
get matchchunk(whateverDataToSearch,"theWordToFind",tStartPosition,tEndPosition)
If a match is found the special variable - it - will contain true, false if the match fails. So if you have a match, tEndPosition will then contain the char position of the last char of the word that was matched.
To delete everything after that word, just
get matchchunk(whateverDataToSearch,"theWordToFind",tStartPosition,tEndPosition)
If a match is found the special variable - it - will contain true, false if the match fails. So if you have a match, tEndPosition will then contain the char position of the last char of the word that was matched.
To delete everything after that word, just
Code: Select all
delete char tEndPosition to -1 of whateverDataWasUsed -- whateverDataWasUsed is the container with the text you are trying to modify.
Re: Delet all characters after word x
Ok have lots to assume here.
Is that what you mean?
Maybe:
Simon
Code: Select all
put "I am a rather fantastic person who enjoys an afternoon at the pub" into tLine
put word 1 to 6 of tLine into tLine
Maybe:
Code: Select all
repeat for each line tLine in tText
put word 1 to 6 of line tLine & cr after tNewText
end repeat
delete last line of tNewText
put tNewText into tText
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: Delet all characters after word x
Thanks Sturgis,
I can use that and get TRUE on "it" but when I answer the tStart and tAnswer variables i get an empty return..
my word to find is a Variable if that matters?
I can use that and get TRUE on "it" but when I answer the tStart and tAnswer variables i get an empty return..
my word to find is a Variable if that matters?
Re: Delet all characters after word x
if it is ALWAYS word 6, definitely go with simons answer.
If you don't know what word it will be, and you removing ALL data after the word (in a multi line set of text) then matchchunk or even wordoffset should work.
To test, I set up 2 fields and a button, Field 1 has some text.
Field 2 is for the output. \
In the button is the following code
Using wordoffset is very similar
But as mentioned, if you need to do this for each single line (a line being delimited by return) definitely go with what simon says. *grin*
If you don't know what word it will be, and you removing ALL data after the word (in a multi line set of text) then matchchunk or even wordoffset should work.
To test, I set up 2 fields and a button, Field 1 has some text.
Field 2 is for the output. \
In the button is the following code
Code: Select all
on mouseUp
put field 1 into tData --put the data into a variable so its faster
get matchchunk(tData,"(variable)",tStart,tEnd) -- look for match. Forgot that parens mark the start end end of the match position that will then go into tStart and tEnd
if it is true then delete char tEnd to -1 of tData -- if there was a match, remove everything to the end
put tData into field 2 -- put the modified text into field 2
end mouseUp
Code: Select all
on mouseup
put field 1 into tData
put wordOffset("variable",tData) into tOffset -- find the first occurrence
if tOffset > 0 then delete word (tOffset + 1) to -1 of tData -- if there was a match, the offset will be > 0 so delete starting at the word AFTER the match, to the end of the text
put tData into field 2 -- put the modified text into field 2
end mouseup
But as mentioned, if you need to do this for each single line (a line being delimited by return) definitely go with what simon says. *grin*
Re: Delet all characters after word x
oops I made a mistake...
should be
But still not sure if I'm answering the question.
It did read to me like it was always word 6, but I get these things wrong often.
Simon
VGhpcyBzdGFydGVkIHdpdGggS2V2aW4gb2YgY291cnNlCldobyBzcG9rZSB0aWxsIGhpcyB2
b2ljZSB3YXMgaG9yc2UKV2l0aCBhIHByb21vdGlvbgpXZSdsbCBnZXQgbXVjaCBtb3JlIG1v
dGlvbgpUaGlzIHNvZnR3YXJlIHdpbGwgZ28gb3BlbiBzb3VyY2U=
Code: Select all
put word 1 to 6 of line tLine & cr after tNewText
Code: Select all
put word 1 to 6 of tLine & cr after tNewText

It did read to me like it was always word 6, but I get these things wrong often.
Simon
VGhpcyBzdGFydGVkIHdpdGggS2V2aW4gb2YgY291cnNlCldobyBzcG9rZSB0aWxsIGhpcyB2
b2ljZSB3YXMgaG9yc2UKV2l0aCBhIHByb21vdGlvbgpXZSdsbCBnZXQgbXVjaCBtb3JlIG1v
dGlvbgpUaGlzIHNvZnR3YXJlIHdpbGwgZ28gb3BlbiBzb3VyY2U=
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: Delet all characters after word x
I'm just glad I got to use the phrase "simon says"
Re: Delet all characters after word x
Another county heard from.
I assume it is not always word 6. This will do the trick yet another way, though there will be problems if the word in question occurs in more than one place. Fortunately, there are simple ways around that as well.
Given a field "yourField" with some text in it, put this in a button somewhere:
This likely needs firming up, as it makes assumptions about your text similar to the comment above. Write back...
Craig Newman
I assume it is not always word 6. This will do the trick yet another way, though there will be problems if the word in question occurs in more than one place. Fortunately, there are simple ways around that as well.
Given a field "yourField" with some text in it, put this in a button somewhere:
Code: Select all
on mouseUp
ask "delete text after which word?"
find it
delete char (word 4 of the foundChunk + 1) to -1 of fld "yourField"
end mouseUp
Craig Newman
Re: Delet all characters after word x
Thanks all,
ended up using Simon's suggestion, not really sure why I didnt look at it from that angle before..
Thanks again..
ended up using Simon's suggestion, not really sure why I didnt look at it from that angle before..
Thanks again..
Re: Delet all characters after word x
Just for another perspective, I'd probably do it this way:
Code: Select all
get wordOffset(tWordToFind,tText)
if it > 0 then delete word it+1 to -1 of tText
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com