Gianni Posted September 13, 2015 Posted September 13, 2015 seems that all regexps from above posts (but jguinch's #9) have issues if $sString begins with something like "| & |" Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
Alex1986 Posted September 13, 2015 Author Posted September 13, 2015 StringRegExpReplace does not have a "searchstring/start" similar in StringReplace#include <String.au3> Local $sString = "|Autoit| , |For| , |All| " local $sReplace[3] = ["ALEX-0" , "ALEX-1" , "ALEX-2"] Local $DATA , $i = 0 $sStringBetween = _StringBetween($sString , "|" , "|") For $x = 0 To UBound($sStringBetween) - 1 If Not BitAND($x,1) Then $DATA &= StringReplace($sString , $sStringBetween[$x] , $sReplace[$i]) & @CRLF $i += 1 EndIf Next Msgbox(0,"", $DATA)this problem repeat |ALEX-0| , |For| , |All||Autoit| , |ALEX-1| , |All||Autoit| , |For| , |ALEX-2|i want this|ALEX-0| , |ALEX-1| , |ALEX-2|
jchd Posted September 13, 2015 Posted September 13, 2015 This?Local $sString = "|Autoit| , |For| , |All| " Local $sReplace[3] = ["ALEX-0" , "ALEX-1" , "ALEX-2"] Local $DATA, $i $DATA = Execute('"' & StringRegExpReplace($sString , '\|[^|]*\|' , '|" & $sReplace[_PostInc($i)] & "|') & '"') Msgbox(0,"", $DATA) Func _PostInc(ByRef $n) $n += 1 Return $n - 1 EndFunc 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)
Alex1986 Posted September 13, 2015 Author Posted September 13, 2015 This?Local $sString = "|Autoit| , |For| , |All| " Local $sReplace[3] = ["ALEX-0" , "ALEX-1" , "ALEX-2"] Local $DATA, $i $DATA = Execute('"' & StringRegExpReplace($sString , '\|[^|]*\|' , '|" & $sReplace[_PostInc($i)] & "|') & '"') Msgbox(0,"", $DATA) Func _PostInc(ByRef $n) $n += 1 Return $n - 1 EndFunc If this $sString Tow Line or more lines , How Replace Example :Local $sString = "|Autoit| , |For| , |All|" & @CRLF & "|Thank| , |You| , |For| , |Help|" Local $sReplace[7] = ["ALEX-1" , "ALEX-2" , "ALEX-3" , "ALEX-4" , "ALEX-5" , "ALEX-6" , "ALEX-7"]
mikell Posted September 13, 2015 Posted September 13, 2015 Did you even test jchd's code with your new requirements ?
iamtheky Posted September 13, 2015 Posted September 13, 2015 and the replace array is not neededLocal $sString = "|Autoit| , |For| , |All|" & @CRLF & "|Thank| , |You| , |For| , |Help|" Local $DATA, $i = 1 $DATA = Execute('"' & StringRegExpReplace($sString , '\|[^|]*\|' , '|" & "ALEX-" & _PostInc($i) & "|') & '"') Msgbox(0,"", $DATA) Func _PostInc(ByRef $n) $n += 1 Return $n - 1 EndFunc ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
jguinch Posted September 13, 2015 Posted September 13, 2015 Without loop :Local $sString = "|Autoit| , |For| , |All|" & @CRLF & "|Thank| , |You| , |For| , |Help|" $DATA = Execute("'" & StringRegExpReplace($sString, "(?<=\|)\h*[^|&,\r\n]+\h*(?=\|)", "Alex' & Eval('__iCount') * Assign('__iCount', Eval('__iCount') + 1) + 1 & '") & "'") Msgbox(0,"", $DATA) iamtheky 1 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
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