Jump to content

StringReplace... mirrored ?


Go to solution Solved by UEZ,

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

Posted

Regexes can save your a$$ everyday!

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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   0 members

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