Jump to content

Recommended Posts

Posted (edited)

Hi guys

I try this for remove specific chars : 

fkz51t.png

#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 by zxtnt09
Posted

Look at the help file for FileOpen.

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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Posted
$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 !!!

x2rjfm.png

( if i click on UTF-8-BOM some of data in file was change ! )

Posted

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)

 

Posted

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

 

Posted (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.

depl3s.png

sorry for bad english.

thanks

Edited by zxtnt09
Posted

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.

Posted (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 by Rampantshadow
Added Quotations

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...