Alex1986 Posted September 12, 2015 Share Posted September 12, 2015 Hii Try Create Code Replace String Between sign "|"Example String" |A| & |B| & |C| & |5|"i Want Replace Just " A B C 5 "Example :#include <String.au3> $String = "|A| & |B| & |C| & |5|" local $TTT $BETW = _StringBetween($String , "|" , "|") For $i = 0 To UBound($BETW) - 1 If Not BitAND($i,1) Then $TTT = $TTT & StringReplace($String , $BETW[$i] , "Hello World !") & @CRLF EndIf Next MsgBox(64 , "" , $TTT)*This code needs correctioni write this Example , But this code Replace With String recurrence , i want Replace don't recurrence Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 12, 2015 Moderators Share Posted September 12, 2015 Alex1986,Perhaps this:$sString = "|A| & |B| & |C| & |5|" $sNewString = StringRegExpReplace($sString, "(^\||\| & \||\|$)", "") ConsoleWrite($sNewString & @CRLF)The RegEx replaces initial and trailing "|" together with all the intermediate "| & |" strings.Is that what you wanted?M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
jguinch Posted September 12, 2015 Share Posted September 12, 2015 Or this :$sString = "|A| & |B| & |C| & |5|" $sNewString = StringRegExpReplace($sString, "[A-Z0-9]", "Hello World !") ConsoleWrite($sNewString & @CRLF)As you can see, your message is not clear enough... Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Alex1986 Posted September 12, 2015 Author Share Posted September 12, 2015 Alex1986,Perhaps this:$sString = "|A| & |B| & |C| & |5|" $sNewString = StringRegExpReplace($sString, "(^\||\| & \||\|$)", "") ConsoleWrite($sNewString & @CRLF)The RegEx replaces initial and trailing "|" together with all the intermediate "| & |" strings.Is that what you wanted?M23this get between , i want replace betweenBefor : "|H| & |B| & |C| & |5|"i do replace "Alex" for allAfter : "|Alex| & |Alex| & |Alex| & |Alex|"Thanks For Help Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 12, 2015 Moderators Share Posted September 12, 2015 Alex1986,Then this should do the trick:$sString = "|A| & |B| & |C| & |5|" $sReplace = "Alex" $sNewString = StringRegExpReplace($sString, "(^|\s)\|.\|(\s|$)", " |" & $sReplace & "| ") ConsoleWrite($sNewString & @CRLF)Look for a string that matches "(start or space) | (any single character) | (Space or end)" and replace it as required.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
jguinch Posted September 12, 2015 Share Posted September 12, 2015 Finally, my code is not so bad... trancexx 1 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Alex1986 Posted September 12, 2015 Author Share Posted September 12, 2015 Or this :$sString = "|A| & |B| & |C| & |5|" $sNewString = StringRegExpReplace($sString, "[A-Z0-9]", "Hello World !") ConsoleWrite($sNewString & @CRLF)As you can see, your message is not clear enough...this Replace Characters[A-Z] & figures[0-9] , But If found other ( * & ^ % $ # ; " ..........etc ) , does not happen properly Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 12, 2015 Moderators Share Posted September 12, 2015 Alex1986,Stop changing the goalposts as the thread progresses!How about this:$sString = "|A&| & |B#| & |*C| & |%5|" $sReplace = "Alex" $sNewString = StringRegExpReplace($sString, "(?U)(^|\s)\|.+\|(\s|$)", " |" & $sReplace & "| ") ConsoleWrite($sNewString & @CRLF)M23 Alex1986 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
jguinch Posted September 12, 2015 Share Posted September 12, 2015 or this (last attempt for me) :$sString = "|A| & |B| & |C| & |5|" $sNewString = StringRegExpReplace($sString, "(?<=\|)\h*[^|&]+\h*(?=\|)", "Alex") ConsoleWrite($sNewString & @CRLF) Alex1986 1 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Alex1986 Posted September 12, 2015 Author Share Posted September 12, 2015 Alex1986,Stop changing the goalposts as the thread progresses!How about this:$sString = "|A&| & |B#| & |*C| & |%5|" $sReplace = "Alex" $sNewString = StringRegExpReplace($sString, "(?U)(^|\s)\|.+\|(\s|$)", " |" & $sReplace & "| ") ConsoleWrite($sNewString & @CRLF)M23thank you very much Melba23 ,this Working Thank you jguinch Link to comment Share on other sites More sharing options...
iamtheky Posted September 12, 2015 Share Posted September 12, 2015 and without regexp. This is provided this string doesnt have a bunch of bonus pipe characters thrown in.$sString = "|A&| & |B#| & |*C| & |%5|" $i = 1 $sMax = stringinstr($sString , "|" , 0 , -1) Do $sFirst = Stringinstr($sString, "|" , 0 , $i) $i += 1 $sSecond = Stringinstr($sString, "|" , 0 , $i) $i += 1 $sString = stringreplace($sString , stringmid($sString , $sFirst + 1 , $sSecond - $sFirst - 1) , "Alex") Until $sSecond >= $sMax msgbox(0, '' , $sString) Alex1986 1 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Alex1986 Posted September 12, 2015 Author Share Posted September 12, 2015 and without regexp. This is provided this string doesnt have a bunch of bonus pipe characters thrown in.$sString = "|A&| & |B#| & |*C| & |%5|" $i = 1 $sMax = stringinstr($sString , "|" , 0 , -1) Do $sFirst = Stringinstr($sString, "|" , 0 , $i) $i += 1 $sSecond = Stringinstr($sString, "|" , 0 , $i) $i += 1 $sString = stringreplace($sString , stringmid($sString , $sFirst + 1 , $sSecond - $sFirst - 1) , "Alex") Until $sSecond >= $sMax msgbox(0, '' , $sString) this best , thank you Link to comment Share on other sites More sharing options...
Alex1986 Posted September 12, 2015 Author Share Posted September 12, 2015 (edited) and without regexp. This is provided this string doesnt have a bunch of bonus pipe characters thrown in.$sString = "|A&| & |B#| & |*C| & |%5|" $i = 1 $sMax = stringinstr($sString , "|" , 0 , -1) Do $sFirst = Stringinstr($sString, "|" , 0 , $i) $i += 1 $sSecond = Stringinstr($sString, "|" , 0 , $i) $i += 1 $sString = stringreplace($sString , stringmid($sString , $sFirst + 1 , $sSecond - $sFirst - 1) , "Alex") Until $sSecond >= $sMax msgbox(0, '' , $sString) There Error $sString = "| Autoit | & | For | & | All |" ;This Not Work ;$sString = "| AA | & | BB | & | CC |" ; This Work $sign = "|" $i = 1 $sMax = stringinstr($sString , $sign , 0 , -1) Do $sFirst = Stringinstr($sString, $sign , 0 , $i) $i += 1 $sSecond = Stringinstr($sString, $sign , 0 , $i) $i += 1 $sString = stringreplace($sString , stringmid($sString , $sFirst + 1 , $sSecond - $sFirst - 1) , "Alex") Until $sSecond >= $sMax MsgBox(64 , "" , $sString) Edited September 12, 2015 by Alex1986 Link to comment Share on other sites More sharing options...
iamtheky Posted September 12, 2015 Share Posted September 12, 2015 I didnt really do any error checking. I think checking $sSecond for a 0 return will fix the issue you found.$sString = "| Autoit | & | For | & | All |" $i = 1 $sMax = stringinstr($sString , "|" , 0 , -1) Do $sFirst = Stringinstr($sString, "|" , 0 , $i) $i += 1 $sSecond = Stringinstr($sString, "|" , 0 , $i) If $sSecond = 0 Then exitloop $i += 1 $sString = stringreplace($sString , stringmid($sString , $sFirst + 1 , $sSecond - $sFirst - 1) , "Alex") ;~ msgbox(0, '' , $sString) Until $sSecond >= $sMax msgbox(0, '' , $sString) ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Alex1986 Posted September 12, 2015 Author Share Posted September 12, 2015 (edited) i test this code , I don't want replace this "YY" $sString = "|Y| & |Y| & YY |Y| " $i = 1 $sMax = stringinstr($sString , "|" , 0 , -1) Do $sFirst = Stringinstr($sString, "|" , 0 , $i) $i += 1 $sSecond = Stringinstr($sString, "|" , 0 , $i) If $sSecond = 0 Then exitloop $i += 1 $sString = stringreplace($sString , stringmid($sString , $sFirst + 1 , $sSecond - $sFirst - 1) , "Alex") ;~ msgbox(0, '' , $sString) Until $sSecond >= $sMax msgbox(0, '' , $sString) Thank you Edited September 12, 2015 by Alex1986 Link to comment Share on other sites More sharing options...
iamtheky Posted September 12, 2015 Share Posted September 12, 2015 (edited) well, by making it harder, you have made it easier. Do not fall in love with one method or the other, just pick the one that fits the job.$sString = "|Y| & |Y| & YY |Y| " msgbox(0, '' , stringreplace($sString , "|Y|" , "|Alex|")) $sString = "|Y| & |Y| & YY |Y| " $aString = stringsplit($sString , "|" , 2) $sOut= "" For $y in $aString If $y = "Y" then $y = "|Alex|" $sOut &= $y Next msgbox(0, '' ,$sOut) Edited September 12, 2015 by boththose ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Alex1986 Posted September 12, 2015 Author Share Posted September 12, 2015 (edited) well, by making it harder, you have made it easier. Do not fall in love with one method or the other, just pick the one that fits the job.$sString = "|Y| & |Y| & YY |Y| " msgbox(0, '' , stringreplace($sString , "|Y|" , "|Alex|")) i want Replace Between "|" , i Don't Replace "Yes" $sString = "|Y| & |Thank| & Yes |You| " ; $i = 1 $sMax = stringinstr($sString , "|" , 0 , -1) Do $sFirst = Stringinstr($sString, "|" , 0 , $i) $i += 1 $sSecond = Stringinstr($sString, "|" , 0 , $i) If $sSecond = 0 Then exitloop $i += 1 $sString = stringreplace($sString , stringmid($sString , $sFirst + 1 , $sSecond - $sFirst - 1) , "Alex") Until $sSecond >= $sMax Msgbox(0,"",$sString) Edited September 12, 2015 by Alex1986 Link to comment Share on other sites More sharing options...
Gianni Posted September 12, 2015 Share Posted September 12, 2015 <snip>i want Replace Between "|" , i Don't Replace "Yes" <snip>??? what's your final goal?Local $sString = "|Y| & |Thank| & Yes |You| " ; Local $sReplace = "Alex" Local $array = StringSplit($sString, "|") For $i = 1 To UBound($array) - 1 If Not StringInStr($array[$i], "&") Then $sString = StringReplace($sString, "|" & $array[$i] & "|", "|" & $sReplace & "|") Next ConsoleWrite($sString & @CRLF) Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Malkey Posted September 13, 2015 Share Posted September 13, 2015 ...... $sMax = stringinstr($sString , "|" , 0 , -1) Do ... With each loop, it is highly likely the value of $sMax will change. Because on each loop the length of $sString might change with each string replacement.It would be better to have the assignment of the value to $sMax inside the loop. And another example.$sString = "|Y| & | Thank | & Yes |You| " $sReplace = "Alex" ConsoleWrite(_StringInsertBetween($sString, "|", "|", $sReplace) & @LF) ; Returns: |Alex| & | Alex | & Yes |Alex| ConsoleWrite(_StringInsertBetweenEx($sString, "|", "|", $sReplace) & @LF) ; Returns: |Alex| & |Alex| & Yes |Alex| ;Conserve spaces. Func _StringInsertBetween($sString, $sStart, $sEnd, $sInsert) Return StringRegExpReplace($sString, "(\Q" & $sStart & "\E\h*)(.*?)(\h*\Q" & $sEnd & "\E)", "${1}" & $sInsert & "${3}") EndFunc ;==>_StringInsertBetween ;Disregard spaces. Func _StringInsertBetweenEx($sString, $sStart, $sEnd, $sInsert) Return StringRegExpReplace($sString, "(\Q" & $sStart & "\E)(.*?)(\Q" & $sEnd & "\E)", "${1}" & $sInsert & "${3}") EndFunc ;==>_StringInsertBetweenEx Link to comment Share on other sites More sharing options...
iamtheky Posted September 13, 2015 Share Posted September 13, 2015 indeed, it has many more problems as well. But it pimps that one string. ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
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