Jump to content

replace string between text


Recommended Posts

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
Link to comment
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.
Link to comment
Share on other sites

$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.
Link to comment
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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
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.
Link to comment
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:
Link to comment
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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
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!"

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...