Delete Last Word

Discussions and Tech Support specific to the iMacros Firefox add-on.
Forum rules
iMacros EOL - Attention!

The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.

Thank you again for your business and support.

Sincerely,
The Progress Team

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: 10301
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'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- 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: 10301
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'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- 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
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Delete Last Word

Post by chivracq » Fri Apr 24, 2020 2:35 pm

ERN645 wrote:
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

Hum @ERN645, I see you are Online checking the Forum right now, so I do a mini-Check on your previous Thread(s) and I notice you never finished this one "correctly" and useful for other Users by sharing the/your Solution..., which would/will be a Condition for me a "next time" if you ever need some Help from the Forum, to help you again..., just saying... :idea:
(And you'll then still have to finish this one correctly first, and then have to wait for the same amount of time the Forum Community will have been waiting for your Solution/Final Script... :P )

And I had asked you twice, => 3x times now, to mention your FCI, but you didn't react/comply... :roll:

>>>

:!: And if you ever open (a) New Thread(s), make sure to open your Thread(s) in the correct Sub-Forum or I don't answer/help, this one for example had nothing specific to the 'iMacros for FF' Sub-Forum, but that was also the Case for the Original Thread, so I didn't say anything about it at that time..., even if your Part had not much related to the Original Thread...

I'm actually "nearly" surprised I had approved your 1st Post in this Thread and didn't ask you rather to open your own Thread..., but I think I was a bit "busy" at that time in the Summer 2019 at some Music Festival (I'm actually a DJ IRL...) and only had limited Internet so I could only check the Forum from time to time to quickly approve the 1st time Posts from New Users that were a bit OK for the Forum, no Spam etc..., without being too strict on the Quality, or you would have had to wait for a few days before your 1st Post got approved... 8)

I will actually ask the Forum Admin to split this Thread to bring your "Part" in a Standalone Thread and to move it to the 'Data Extraction' Sub-Forum where it rather belongs... :wink:
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
Post Reply