Sign in to follow this  
Followers 0
personant

replace string between text

17 posts in this topic

#1 ·  Posted (edited)

I'm new in autoit...

so how to replace string between fexp= and &algorithm to 907605

for an example :

before = fexp=1234,5678&algorithm

after = fexp=907605&algorithm

please help me... :huh2:

Edited by personant

Share this post


Link to post
Share on other sites



$stringold="1234,5678&algorithm" 
$string=StringTrimLeft ($stringold,10) 
$stringnew="907605" & $string


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

hope it works :huh2:


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

$input=inputbox("title","prompt")
$string=$input & "&algorithm"

This can be done too...


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

$stringold="1234,5678&algorithm" 
$string=StringTrimLeft ($stringold,10) 
$stringnew="907605" & $string

the 1234,5678 is just an example.... the string between the text could be short or long, so the trim script would not work

Share this post


Link to post
Share on other sites

yes....so what about the second script... ?


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

yes....so what about the second script... ?

I want it to be automatic... :huh2:

Share this post


Link to post
Share on other sites

$original="1234,5678&algorithm"
$pos=stringinstr ($original,"&algorithm",0)
$replacment="907605"
$new=$replacment & stringtrimleft ($original,$pos-1)


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

does '&algorithm' always come at the end of the string ?? if yes, the above script can be used :huh2:


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

like I just said... the string between the text could be anything... so I need an universal script

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

$original="1234,5678&algorithm"
$pos=stringinstr ($original,"&algorithm",0)
$replacment="907605"
$new=$replacment & stringtrimleft ($original,$pos-1)

almost works as a universal script if you have '&algorithm' at the end...

just change $original to any other variable text with '&algorithm' at the end and $replacement with other number and it works as you required...

:huh2:

Edited by Shaarad

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

$before = "fexp=1234,5678&algorithm"
$replace_with = "907605"
$after = StringReplace(StringRegExpReplace($before, "(fexp=)(.*)(&algorithm)", "$1 " & $replace_with & "$3"), "= ", "=")
MsgBox(0, "Test", $after)

$after = StringReplace($before, StringMid($before, 6, StringInStr($before, "&algorithm") - 6), $replace_with)
MsgBox(0, "Test", $after)

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

I need to work hard on the StringRegExp and StringRegExpReplace... :huh2:


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

$before = "fexp=1234,5678&algorithm"
$replace_with = "907605"
$after = StringReplace(StringRegExpReplace($before, "(fexp=)(.*)(&algorithm)", "$1 " & $replace_with & "$3"), "= ", "=")
MsgBox(0, "Test", $after)

$after = StringReplace($before, StringMid($before, 6, StringInStr($before, "&algorithm") - 6), $replace_with)
MsgBox(0, "Test", $after)

Br,

UEZ

Thanks UEZ for the script.. works like a charm :huh2:

Share this post


Link to post
Share on other sites

$after = StringReplace(StringRegExpReplace($before, "(fexp=)(.*)(&algorithm)", "$1 " & $replace_with & "$3"), "= ", "=")

Just a little modification to avoid the first StringReplace :huh2:

$after = StringRegExpReplace($before,  "(fexp=)(.*)(&algorithm)", "${1}" & $replace_with & "$3")

Share this post


Link to post
Share on other sites

@sahsanu: that's what I searched for ${1} and used the StringReplace as a workaround!

Thanks for it!

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

I need to work hard on the StringRegExp and StringRegExpReplace... :huh2:

There is a tool in my signature to help you with that.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0