zxtnt09 Posted January 3, 2016 Share Posted January 3, 2016 (edited) Hi guysI try this for remove specific chars : #include <File.au3> $FileDir = "test.txt" $String = chr(0) _ReplaceStringInFile($FileDir,$String,"Hello") $FileOpen = FileOpen($FileDir) $FileRead = FileReadLine($FileDir,4) MsgBox(0,0,$FileRead) $FileClose = FileClose($FileDir)=============================Update :i found problem it's for encode , but how can i change file encode to "UTF-8-BOM" Edited January 3, 2016 by zxtnt09 Link to comment Share on other sites More sharing options...
guinness Posted January 3, 2016 Share Posted January 3, 2016 Look at the help file for FileOpen. zxtnt09 1 UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
InunoTaishou Posted January 3, 2016 Share Posted January 3, 2016 zxtnt09 1 Link to comment Share on other sites More sharing options...
zxtnt09 Posted January 3, 2016 Author Share Posted January 3, 2016 Look at the help file for FileOpen.i use that but still don't action !$FileOpen = FileOpen($FileDir,256) Link to comment Share on other sites More sharing options...
Trong Posted January 3, 2016 Share Posted January 3, 2016 $hFileOpen = FileOpen($sFile,16); $FO_BINARY (16) = Force binary mode Regards, Link to comment Share on other sites More sharing options...
zxtnt09 Posted January 3, 2016 Author Share Posted January 3, 2016 $hFileOpen = FileOpen($sFile,16); $FO_BINARY (16) = Force binary mode Still not working !!!!!important part for me is "String repleace" , i need to repleace "NULL" to "Hello" but not working,for do that , i should open file and click on "UTF-8-BOM" after i click that i can replace !!!( if i click on UTF-8-BOM some of data in file was change ! ) Link to comment Share on other sites More sharing options...
Malkey Posted January 3, 2016 Share Posted January 3, 2016 You could try this.; Create test file "fkz51t.txt" Local $hFileOpen = FileOpen("fkz51t.txt", 2) Local $FileContents = _ ChrW(0) & ChrW(0) & ChrW(0) & ChrW(5) & ChrW(3) & @CRLF & _ ChrW(0) & ChrW(0) & ChrW(0) & ChrW(0) & ChrW(4) & @CRLF & _ ChrW(0) & ChrW(0) & ChrW(0) & ChrW(0) & ChrW(4) & @CRLF & _ ChrW(0) & ChrW(0) & ChrW(0) & ChrW(0) & ChrW(4) FileWrite($hFileOpen, $FileContents) FileClose($hFileOpen) ; Replace Null with "Hello" Local $hFileOpen = FileOpen("fkz51t.txt", 16) Local $data = StringReplace(FileRead($hFileOpen), "00", StringTrimLeft(StringToBinary("Hello"), 2)) ; "00" (binary) = ChrW(0) = null FileClose($hFileOpen) FileDelete("fkz51t.txt") ; Write modified file contents to file FileWrite("fkz51t.txt", BinaryToString($data)) ; Display contents of file. ConsoleWrite(FileRead("fkz51t.txt") & @LF) zxtnt09 1 Link to comment Share on other sites More sharing options...
zxtnt09 Posted January 3, 2016 Author Share Posted January 3, 2016 @Malkey , thanks it's great but have a little problem and it's clear all of other file content!it's meant : "in this file we have" NULL NULL NULL NULL NULL BS NULL NULL NULL NULL SOH ETB NULL Some data 2015 blah blah ; the data by each refresh will be change , but i want to clean just null not all of content Link to comment Share on other sites More sharing options...
Malkey Posted January 3, 2016 Share Posted January 3, 2016 This example removes only null characters. This works for me on Win 10.; Create test file "fkz51t.txt". Local $sFileName = "fkz51t.txt" Local $hFileOpen = FileOpen($sFileName, 2) Local $FileContents = _ ChrW(0) & ChrW(0) & ChrW(0) & ChrW(0) & ChrW(0) & ChrW(8) & @CRLF & _ ChrW(0) & ChrW(0) & ChrW(0) & ChrW(0) & ChrW(1) & ChrW(23) & @CRLF & _ ChrW(0) & "Some data 2015 blah blah" FileWrite($hFileOpen, $FileContents) FileClose($hFileOpen) ; Remove all Nulls. Local $hFileOpen = FileOpen($sFileName, 16) Local $data = StringReplace(FileRead($hFileOpen), "00", "") ; Replace all "00" (binary) with "" (nothing). FileClose($hFileOpen) FileDelete($sFileName) ; Write modified file contents to file. FileWrite("fkz51t.txt", BinaryToString($data)) ; Display contents of file. ConsoleWrite(FileRead("fkz51t.txt") & @LF) Returns the file contents of:-BS SOH ETB Some data 2015 blah blah Link to comment Share on other sites More sharing options...
zxtnt09 Posted January 4, 2016 Author Share Posted January 4, 2016 (edited) BS SOH ETB �Some data 2015 blah blah yes it's true , but it was overwrite and remove all of things ( without data in "Local $FileContents" )actuley i don't know "some data 2015 blah blah ..." it was modify by each refresh! ( example : going to "some data 2016 halb blah" )so i should repleace "NULL" and "SOH" with "Blank".please see this , the data will be modify by each refresh , so i should remove just "NULL" and other data (the data i don't know) should not be remove.sorry for bad english.thanks Edited January 4, 2016 by zxtnt09 Link to comment Share on other sites More sharing options...
zxtnt09 Posted January 5, 2016 Author Share Posted January 5, 2016 up Link to comment Share on other sites More sharing options...
Rampantshadow Posted January 5, 2016 Share Posted January 5, 2016 what would be the ideal data that you would like left in the file? just the date for example, or did you just want to get rid of the blanks and leave all other data? Link to comment Share on other sites More sharing options...
zxtnt09 Posted January 5, 2016 Author Share Posted January 5, 2016 what would be the ideal data that you would like left in the file? just the date for example, or did you just want to get rid of the blanks and leave all other data? Yes it's true , i want to change (repleace) just "NULL" data and leave other data. Link to comment Share on other sites More sharing options...
Rampantshadow Posted January 5, 2016 Share Posted January 5, 2016 (edited) firstly if you want to open the file in UTF8-BOM you need to$FileOpen = FileOpen("test.txt", 1 + 256) ;This will allow you to Append the File and open it in UTF8-BOM $string = FileRead($FileOpen) FileClose($FileOpen) $charReplace = StringReplace($string,'NUL',"",0) FileDelete("test.txt") $FileOpen = FileOpen("test.txt", 2) ;this will write an new file not saved as UTF8-BOM but as ANSI FileWrite($FileOpen,$charReplace)Hopefully this should work for what you need it to do, I honestly haven't tested it but it should be close to what you want. Edited January 5, 2016 by Rampantshadow Added Quotations 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