madsiddiqui Posted September 9, 2011 Posted September 9, 2011 (edited) #include <String.au3> ;declerations here $hFile = FileOpen("Test.bin", 18) $hFile2 = FileOpen("Test2.bin", 0) $chars = FileRead($hFile2) $SH = StringReplace(StringReplace(StringReplace(StringReplace(StringReplace(StringReplace(StringReplace(StringReplace($chars, "", @TAB, 0 ,1), "", @CRLF, 0 ,1), "9" ,"-", 0 ,1), "4" ," ", 0 ,1), "7" ,"#", 0 ,1), "$" ,"0", 0 ,1), "%" ,"1", 0 ,1), "h" ,"|", 0 ,1) $bString = _StringToHex($SH) FileWrite($hFile, _HexToString($bString)) FileClose($hFile) Any advise on how to make the string replace a bit better than that? very messy. I have to add around 100+ strings to be replaced. Another thing is, on my replace. I will replace all 4 to {space}, and all {space} to 4.. But when I do this, all {space} just becomes 4, and the 4 remains a 4, not replaced to {space}. Replace all 4 => {space} Replace all {space} => 4 Replace all $ => 0 Replace all 0 => $ How to do that? Thank you. Edited September 9, 2011 by madsiddiqui
GEOSoft Posted September 9, 2011 Posted September 9, 2011 $sH = FileRead("SomeFile.bin") $sH = StringRegExpReplace($sH, "([\h4\$0])(\h*=>\h*)([\h4\$0])", "$3$2$1") George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
Moderators Melba23 Posted September 9, 2011 Moderators Posted September 9, 2011 madsiddiqui, I would set out the required replacement values in an array and then work through the string like this: #include <Array.au3> ; Here you define the originals and their replacements Global $aReplacements[2][2] = [["4", "o"], ["o", "4"]] $sText = "-o4-o4-4o-4o-" $sNewText = "" ; Now run through the string For $i = 1 To StringLen($sText) $sChar = StringMid($sText, $i, 1) $iIndex = _ArraySearch($aReplacements, $sChar) If @error Then ; If not found add the character $sNewText &= $sChar Else ; If found add replacement $sNewText &= $aReplacements[$iIndex][1] EndIf Next ; And here is the result ConsoleWrite($sText & @CRLF & $sNewText & @CRLF) Any help? 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
GEOSoft Posted September 9, 2011 Posted September 9, 2011 Did you jump ship? George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
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