Delete Last Word

Discussions and Tech Support related to the iMacros Firefox Add-on, including the built-in Javascript scripting interface for playing .js files.
Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
Maxal
Posts: 32
Joined: Sun Feb 08, 2015 4:27 pm

Delete Last Word

Post by Maxal » Sun Feb 08, 2015 7:17 pm

Hey

I am new to almost everything under the sun, especially if it is scripting :) Installed iMacro and trying to see how it could help me.

I am using an iMacro which pastes text in a text area. I want to know how I could make the iMacro to delete the last word of the pasted text.

Thanx
Max
skippyto
Posts: 108
Joined: Wed Aug 20, 2008 8:14 am

Re: Delete Last Word

Post by skippyto » Tue Feb 10, 2015 8:54 am

Hi Maxal !

You can extract the content of the text area (TAG ... EXTRACT=TXT)

Then with EVAL you can eval the size of the last word from the extract, and prepare the number of press on the delete key for the keypress command.

A least you play the keypress command.

Example of code that works on this forum (I suppose there is a space before the last word) :

Code: Select all

' Extract the content of the text area
TAG POS=1 TYPE=TEXTAREA FORM=ID:postform ATTR=ID:message EXTRACT=TXT
' Lenght of the last word + the space before it
SET !VAR1 EVAL("var e=\"{{!EXTRACT}}\"; (e.toString().length - e.toString().lastIndexOf(\" \"));")
' Prepare the good numbers of delete for the keypress command
SET !VAR2 EVAL("var t=\"\"; for(i=0; i<=parseInt(\"{{!VAR1}}\"); i++){t+=\"8,\"};t=t.substring(0, t.length-1);")
' Delete the last word and the space before it
EVENTS TYPE=KEYPRESS SELECTOR="#message" KEYS="[{{!VAR2}}]"
Skippyto
Maxal
Posts: 32
Joined: Sun Feb 08, 2015 4:27 pm

Re: Delete Last Word

Post by Maxal » Sat Feb 21, 2015 3:13 pm

Hey skippyto, thanks for the code. But I guess it won't work in my peculiar case.

I have to paste text in a text box which trims anything beyond 400 characters, this often leaves last word cut in half. For instance, if the limit of 400 characters ends and a word is incomplete, it will be iMac instead of iMacro because ro are 2 excessive characters. And issue is that the box trims the character only if I click inside the box. If I paste the text through iMacro, the box doesn't trim the text to 400 characters which is a must.

I am not sure if it is possible or not, but in short, what I want is that iMacro pastes the text into the box, than hit a click inside it so that text is trimmed to 400 characters, and only then it removes the very last word which may be a half word. That's the whole scenario.

Thanks again for your help skippyto :)
ERN645
Posts: 3
Joined: Tue Aug 27, 2019 2:56 pm

Re: Delete Last Word

Post by ERN645 » Tue Aug 27, 2019 3:01 pm

Maybe know how need delete space from this code.
When i extraxt number i got numbers with space
space is before numbers, maybe can make fix problem

VERSION BUILD=1005 RECORDER=CR
SET !EXTRACT_TEST_POPUP NO
TAG XPATH="//*[@id="a-page"]/div[3]/div[1]/div/div/div/div/div[1]/h5" EXTRACT=TXT
SET !VAR1 EVAL("var variable=\"{{!EXTRACT}}\"; variable.replace(/Order Number:/g,''); ")
WAIT SECONDS=3
TAB CLOSE
WAIT SECONDS=3
TAG SELECTOR="#modal_buy_order_id" CONTENT={{!VAR1}}
TAG SELECTOR="#modal-6>DIV>DIV>DIV:nth-of-type(2)>DIV:nth-of-type(7)>DIV>DIV"
TAG POS=1 TYPE=BUTTON ATTR=ID:save_order_changes
TAG POS=1 TYPE=BUTTON ATTR=TXT:Change<SP>Details
chivracq
Posts: 8781
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Delete Last Word

Post by chivracq » Tue Aug 27, 2019 3:34 pm

ERN645 wrote:
Tue Aug 27, 2019 3:01 pm
Maybe know how need delete space from this code.
When i extraxt number i got numbers with space
space is before numbers, maybe can make fix problem

Code: Select all

VERSION BUILD=1005 RECORDER=CR
SET !EXTRACT_TEST_POPUP NO
TAG XPATH="//*[@id="a-page"]/div[3]/div[1]/div/div/div/div/div[1]/h5" EXTRACT=TXT
SET !VAR1 EVAL("var variable=\"{{!EXTRACT}}\"; variable.replace(/Order Number:/g,''); ")
WAIT SECONDS=3
TAB CLOSE
WAIT SECONDS=3
TAG SELECTOR="#modal_buy_order_id" CONTENT={{!VAR1}}
TAG SELECTOR="#modal-6>DIV>DIV>DIV:nth-of-type(2)>DIV:nth-of-type(7)>DIV>DIV"
TAG POS=1 TYPE=BUTTON ATTR=ID:save_order_changes
TAG POS=1 TYPE=BUTTON ATTR=TXT:Change<SP>Details

FCIM...! :mrgreen: (Read my Sig...)
=> iMacros for CR v10.0.5, 'Free'/'PE'...?, CR77...?, OS...?

Fouff...!, I'm not sure I understand exactly what you mean/want... :?

But if I understand "correctly", that you get for example in the 'EXTRACT' => "Order Number: 1234", and you only want to keep "1234" and not " 1234", (=> without the leading Space), simply include that Space in the 'replace()', I would think:

Code: Select all

SET !VAR1 EVAL("var variable=\"{{!EXTRACT}}\"; variable.replace(/Order Number: /g,''); ")
You could also use 'trim()' and/or 'split()'..., and your 'replace()' probably doesn't need to be /global/...
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
ERN645
Posts: 3
Joined: Tue Aug 27, 2019 2:56 pm

Re: Delete Last Word

Post by ERN645 » Tue Aug 27, 2019 4:21 pm

Maybe you can help and write code for me please,
i try but all time got errror , i try many metods

for me i got resilt

123-54125478445
but i want to make like it but with out scpase before numbers
123-54125478445
chivracq
Posts: 8781
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Delete Last Word

Post by chivracq » Tue Aug 27, 2019 5:58 pm

ERN645 wrote:
Tue Aug 27, 2019 4:21 pm
Maybe you can help and write code for me please,
i try but all time got errror , i try many metods

for me i got resilt

Code: Select all

                               123-54125478445
but i want to make like it but with out scpase before numbers

Code: Select all

123-54125478445

Yeah but you missed the "FCIM" part for me to follow up... :roll:

"Maybe you can help" => As far as I can tell, I'm already helping you...!! :roll: And nope, I don't write Code for other Users (or very rarely), I let you (and other Users searching the Forum with a similar Qt/Scenario) understand "what you are doing [wrong]" and find the Solution by yourself... :wink:

"but all time got er[r]ror" is pretty vague and not very helpful if you don't mention which Error(s)...!?, and together with the "many met[h]ods" that you tried, ah-ah...!? :roll:

And try to put some mini-Effort into your Posts and to improve a bit the "Quality", your English is already a bit "approx" to understand, but nearly every Word you type contains also one or more Typos... :roll:
And the Spaces are not visible if you don't use any Delimiters or some Formatting like I did in my Quote...
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
ERN645
Posts: 3
Joined: Tue Aug 27, 2019 2:56 pm

Re: Delete Last Word

Post by ERN645 » Wed Aug 28, 2019 3:25 am

Ok.
Maybe help if i add second var with remove space?
Sorry for it i here new and imacros use only 4 days jet
Post Reply