Jump to content

Recommended Posts

  • argumentum changed the title to StringReplace... mirrored ?
Posted (edited)
Exit test2()
Func test2() ; my solution. ..thanks to @quymao2 for the enlightment  =)
    Local $sStr = "a ''' 123 ''' b ''' 234 ''' c"
    While StringInStr($sStr, "'''")
    $sStr = StringReplace($sStr, "'''", "*'", 1)
    $sStr = StringReplace($sStr, "'''", "'*", 1)
    WEnd
    ConsoleWrite(@CRLF & $sStr & @CRLF & @CRLF) ; ' a *' 123 *' b '
EndFunc ; v2


Exit test()
Func test()
;~     Local $sStr = "a ''' 123 ''' b" ; a *' 123 '* b ; good
    Local $sStr = "a ''' 123 ''' b ''' 234 ''' c" ; a *' 123 *' b '* 234 '* c ; =(....
    ConsoleWrite(@CRLF & StringReplace(StringLeft($sStr, StringLen($sStr)/2+1), "'''", "*'") & StringReplace(StringRight($sStr, StringLen($sStr)/2),  "'''", "'*") & @CRLF & @CRLF) ; ' a *' 123 *' b '
EndFunc

yes, but if I want to do a longer string ... :(
@quymao2 gave me "a north" ( as Cubans say ), hence this solution :) 

Edited by argumentum
v2

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

  • Solution
Posted
Func test3()
    Local $sStr = "a ''' 123 ''' b ''' 234 ''' c"
    ConsoleWrite(StringRegExpReplace($sStr, "'''([^']+)'''", "*'$1'*") & @CRLF)
EndFunc

 

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

Posted
10 minutes ago, quymao2 said:

sorry , i did not got what you said clearly. this my way in your case :

Local $sStr = "a ''' 123 ''' b ''' 234 ''' c"
 $out = StringRegExpReplace($sStr,"\'{3}\s(\d+)\s\'{3}","\*\' $1 \'\*")
 ConsoleWrite($out)

 

 

"'''([^']+)'''", "*'$1'*"

[^'] means: any character except a single quote

+ means: one or more times

So this matches everything between the triple quotes like ''' 123 ''' and replace it with *' 123 '* (using *'$1'*).

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

Posted (edited)
18 minutes ago, quymao2 said:

sorry , i did not got what you said clearly. this my way in your case :

Local $sStr = "a ''' 123 ''' b ''' 234 ''' c'''345'''d"
$out = StringRegExpReplace($sStr,"\'{3}\s(\d+)\s\'{3}","\*\' $1 \'\*") ; a *' 123 '* b *' 234 '* c'''345'''d
ConsoleWrite(@CRLF & $out & @CRLF & @CRLF) ; a *' 123 '* b *' 234 '* c'''345'''d

...but wait, there is more ! ( in TV commercial advertisement they use the "..but wait, there is more.." ) :D
For a string of an unknown number of these ''' pairs, @UEZ's regex works best :) 

Edit: we posted quite consecutively :) 

Edited by argumentum

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

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
  • Recently Browsing   1 member

×
×
  • Create New...