Declaration
Automation:
void  Replace ( [in]   ulong  Offset, [in]   uint  size_from, [in]   ref byte  pTo, [in]   uint  size_to) ;
Native (C++):
HRESULT  Replace ( [in]   unsigned __int64  Offset, [in]   unsigned long  size_from, [in]   unsigned char *  pTo, [in]   unsigned long  size_to) ;
Parameters
OffsetReplace offsetsize_fromSize of the original patternpToPointer to a replace patternsize_toSize of the replace pattern
Return Value
S_OK or standard OLE error code.
Remarks
Replaces the given block with a pattern. This method replaces a range described by Offset and size_from parameters with a pattern. Complexity: constant-time.
Examples

Replacing a pattern

C#Copy Code
FileDocumentLib.FileDocument fdoc = new FileDocumentLib.FileDocument();
FileDocumentLib.IMultiSelection msec = fdoc.CreateEmptySelection();

fdoc.Open(@"c:\temp\file.txt");
msec.AddRange(0, fdoc.FileSize);  // We'll be searching in a whole file

byte[] pattern1 = new byte[] { 0x0d, 0x0a }; // EOL pattern
byte[] pattern2 = new byte[] { 0x0d, 0x0a, 0x0d, 0x0a }; // Double-EOL pattern
ulong EOL_Offset = fdoc.Find(ref pattern1[0], pattern1.Length, msel, 0, false, false);
if (EOL_Offset != -1)
  fdoc.Replace(EOL_Offset, pattern1.Length, ref pattern2[0], pattern2.Length);