Jump to content

How to replace in binary string?


E1M1
 Share

Recommended Posts

How to replace placeholder in rtf file and put it to clipboard? I still get contents with {name} instead of Some Replacement. Note that last char of this rtf file is NUL.

 

#include <Clipboard.au3>
#include <String.au3>
_Example()
Func _Example()
    Local $sRTF_FileFullPath = @ScriptDir & '\outfile.rtf'
    Local $hFile = FileOpen($sRTF_FileFullPath)
    Local $sRTF_Content = FileRead($hFile)
    $sRTF_Content = StringReplace($sRTF_Content,"\{name\}", "Some Replacement")
    FileClose($hFile)
    Local $iClipboardFormat = _ClipBoard_RegisterFormat("Rich Text Format")
    Local $hMemory = _ClipBoard_SetData($sRTF_Content, $iClipboardFormat)
EndFunc

 

outfile.rtf

Edited by E1M1

edited

Link to comment
Share on other sites

Hi.

explicitely open as UTF8:

 

#include <Clipboard.au3>
#include <String.au3>
#include <FileConstants.au3>

_Example()
Func _Example()
    Local $sRTF_FileFullPath = "c:\temp\test-outfile.rtf"
    Local $hFile = FileOpen($sRTF_FileFullPath,$FO_UTF8)
    Local $sRTF_Content = FileRead($hFile)
    $sRTF_Content = StringReplace($sRTF_Content,"\{name\}", "Some Replacement")
    FileClose($hFile)
    ConsoleWrite($sRTF_Content & @CRLF)
    Exit
    Local $iClipboardFormat = _ClipBoard_RegisterFormat("Rich Text Format")
    Local $hMemory = _ClipBoard_SetData($sRTF_Content, $iClipboardFormat)
EndFunc

 

>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\temp\replace-test.au3" /UserParams    
+>15:32:47 Starting AutoIt3Wrapper v.17.224.935.0 SciTE v.3.7.3.0   Keyboard:00000407  OS:WIN_7/Service Pack 1  CPU:X64 OS:X64  Environment(Language:0407)  CodePage:0  utf8.auto.check:4
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\admin\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\admin\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.5)  from:C:\Program Files (x86)\AutoIt3  input:C:\temp\replace-test.au3
+>15:32:47 AU3Check ended.rc:0
>Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\temp\replace-test.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
{\rtf1\ansi\ansicpg1257\deff0\deflang1061{\fonttbl{\f0\fswiss\fprq2\fcharset186 Calibri;}{\f1\fnil\fcharset0 Calibri;}}
{\colortbl ;\red31\green73\blue125;}
{\*\generator Msftedit 5.41.21.2510;}\viewkind4\uc1\pard\cf1\f0\fs22 Hello Some Replacement good to see you!\cf0\lang1033\f1\par
}
+>15:32:47 AutoIt3.exe ended.rc:0
+>15:32:47 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 0.6682

 

regards, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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