argumentum Posted October 2 Posted October 2 (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 October 2 by argumentum Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
quymao2 Posted October 2 Posted October 2 (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 October 2 by quymao2 argumentum 1
argumentum Posted October 2 Author Posted October 2 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 October 2 Posted October 2 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 October 2 Author Posted October 2 (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 October 2 by argumentum v2 quymao2 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Solution UEZ Posted October 2 Solution Posted October 2 Func test3() Local $sStr = "a ''' 123 ''' b ''' 234 ''' c" ConsoleWrite(StringRegExpReplace($sStr, "'''([^']+)'''", "*'$1'*") & @CRLF) EndFunc argumentum and Danyfirex 2 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 October 2 Posted October 2 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 October 2 Posted October 2 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 October 2 Author Posted October 2 (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 October 2 by argumentum Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
jchd Posted October 3 Posted October 3 Regexes can save your a$$ everyday! argumentum and Danyfirex 2 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 hereRegExp tutorial: enough to get startedPCRE 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)
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