argumentum Posted 13 hours ago Posted 13 hours ago (edited) Exit test() Func test() Local $sStr = "a ''' 123 ''' b" ConsoleWrite(@CRLF & StringReplace($sStr, "''", "*") & @CRLF & @CRLF) ; ' a *' 123 *' b ' EndFunc That returns: ' a *' 123 *' b ' but I need ' a *' 123 '* b ' Edited 12 hours ago by argumentum Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
quymao2 Posted 12 hours ago Posted 12 hours ago (edited) In your original string you have three ''', but in seaching parameter of String Replace, you put only two '' :)) the correct format is must be ConsoleWrite(@CRLF & StringReplace($sStr, "'''", "*") & @CRLF & @CRLF) ; ' a *' 123 *' b ' Edited 12 hours ago by quymao2 argumentum 1
argumentum Posted 12 hours ago Author Posted 12 hours ago 13 minutes ago, quymao2 said: ..the correct format is must be .. Actually, I'd like to replace '' and not ''' but, I'd like the 2nd *' to be '* 😭 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Werty Posted 12 hours ago Posted 12 hours ago Exit test() Func test() Local $sStr = "a ''' 123 ''' b" ConsoleWrite(@CRLF & StringReplace(StringLeft($sStr, StringLen($sStr)/2+1), "'''", "*'") & StringReplace(StringRight($sStr, StringLen($sStr)/2), "'''", "'*") & @CRLF & @CRLF) ; ' a *' 123 *' b ' EndFunc Not pretty but works 😛 argumentum 1 Some guy's script + some other guy's script = my script!
argumentum Posted 12 hours ago Author Posted 12 hours ago (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 11 hours ago by argumentum v2 quymao2 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Solution UEZ Posted 10 hours ago Solution Posted 10 hours ago Func test3() Local $sStr = "a ''' 123 ''' b ''' 234 ''' c" ConsoleWrite(StringRegExpReplace($sStr, "'''([^']+)'''", "*'$1'*") & @CRLF) EndFunc argumentum 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
quymao2 Posted 10 hours ago Posted 10 hours ago 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) argumentum 1
UEZ Posted 10 hours ago Posted 10 hours ago 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'*). argumentum 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
argumentum Posted 10 hours ago Author Posted 10 hours ago (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.." ) For a string of an unknown number of these ''' pairs, @UEZ's regex works best Edit: we posted quite consecutively Edited 10 hours ago by argumentum Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now