Replaces all found matches of string "whatReplaceInRtf" by the string "wherewithReplaceInRtf" and returns a new RTF document

Namespace:  SautinSoft
Assembly:  SautinSoft.HtmlToRtf (in SautinSoft.HtmlToRtf.dll) Version: 5.8.2.8

Syntax

      
 C#  Visual Basic 
public string MergeAndReplaceRtfString(
	string rtfSource,
	string whatReplaceInRtf,
	string wherewithReplaceInRtf
)
Public Function MergeAndReplaceRtfString ( _
	rtfSource As String, _
	whatReplaceInRtf As String, _
	wherewithReplaceInRtf As String _
) As String

Parameters

rtfSource
String
Source RTF document where to search matches of "whatReplaceInRtf"
whatReplaceInRtf
String
String in Text or RTF format which will be replaced by the new string "wherewithReplaceInRtf"
wherewithReplaceInRtf
String
String in RTF format which will be used to replace all matches of string "whatReplaceInRtf"

Return Value

A new RTF document based on rtfSource
null - in case of operation failed

Remarks



Examples

CopyInsert one RTF document inside another RTF in memory using C#
using System;
using System.IO;

namespace Sample
{
    class Test
    {

        static void Main(string[] args)
        {
            // Replace values in RTF document
            // If you need more information about "HTML to RTF .Net" email us at:
            // support[at]sautinsoft.com        
            SautinSoft.HtmlToRtf h = new SautinSoft.HtmlToRtf();
            // After purchasing the license, please insert your serial number here to activate the component
            //h.Serial = "XXXXXXXXXXXXXXX";

            DirectoryInfo htmlDir = new DirectoryInfo(@"..\..\..\..\..\..\Testing HTMLs");

            // For example, we've RTF with such content "This is a sample footer as RTF document."
            // Let's replace the string "sample" by another RTF file.

            string sourceRtfFile = Path.Combine(htmlDir.FullName, "footer.rtf");
            string replacingRtfFile = Path.Combine(htmlDir.FullName, "footer.rtf");
            string whatReplace = "sample";
            string resultRtfFile = Path.Combine(htmlDir.FullName, "result.rtf");

            h.MergeAndReplaceRtfFileFromFile(sourceRtfFile, whatReplace, replacingRtfFile, resultRtfFile);

            // Show produced result.
            System.Diagnostics.Process.Start(resultRtfFile);
        }
    }
}
CopyInsert one RTF document inside another RTF in memory using VB.Net
Imports System
Imports System.IO
Imports System.Text

Module Module1
    Sub Main()
        ' Replace values in RTF document
        ' If you need more information about "HTML to RTF .Net" email us at:
        ' support[at]sautinsoft.com        
        Dim h As New SautinSoft.HtmlToRtf()
        ' After purchasing the license, please insert your serial number here to activate the component
        'h.Serial = "XXXXXXXXXXXXXXX";


        Dim htmlDir As New DirectoryInfo("..\..\..\..\..\Testing HTMLs")

        ' For example, we've RTF with such content "This is a sample footer as RTF document."
        ' Let's replace the string "sample" by another RTF file.


        Dim sourceRtfFile As String = Path.Combine(htmlDir.FullName, "footer.rtf")
        Dim replacingRtfFile As String = Path.Combine(htmlDir.FullName, "footer.rtf")
        Dim whatReplace As String = "sample"
        Dim resultRtfFile As String = Path.Combine(htmlDir.FullName, "result.rtf")

        h.MergeAndReplaceRtfFileFromFile(sourceRtfFile, whatReplace, replacingRtfFile, resultRtfFile)

        ' Show produced result.
        System.Diagnostics.Process.Start(resultRtfFile)
    End Sub
End Module

See Also