Replaces all matches of the string "textToReplace" by the string "wherewithReplaceInRtf" and returns a new RTF document.

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

Syntax

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

Parameters

rtfSource
String
Source RTF document where to search matches of "whatReplaceInRtf"
textToReplace
String
Textual string 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 "textToReplace"

Return Value

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

Remarks



Examples

CopyReplace value in RTF document by another RTF using C#
using System;
using System.IO;

namespace Sample
{
    class Test
    {

        static void Main(string[] args)
        {
            // How to replace values in RTF document by another RTF content.
            // If you need more information about "HTML to RTF .Net" email us at:
            // support@sautinsoft.com    
            ReplaceValuesInRtf();
        }

        public static void ReplaceValuesInRtf()
        {
            SautinSoft.HtmlToRtf h = new SautinSoft.HtmlToRtf();

            // After purchasing the license, please insert your serial number here to activate the component.
            // h.Serial = "XXXXXXXXX";

            // 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 = @"..\..\footer.rtf";
            string wherewithReplaceRtfPath = @"..\..\footer.rtf";
            string textToReplace = "sample";
            string resultRtfFile = Path.ChangeExtension(sourceRtfFile, ".result.rtf");
            h.MergeOptions.PageBreakBetweenDocuments = false;
            h.MergeAndReplaceRtfFileFromFile(sourceRtfFile, textToReplace, wherewithReplaceRtfPath, resultRtfFile);

            // Show the result.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(resultRtfFile) { UseShellExecute = true });
        }
    }
}
CopyReplace value in RTF document by another RTF using VB.Net
Imports System
Imports System.IO
Imports System.Text

Module Module1
    Sub Main()
        ' How to replace values in RTF document by another RTF content.
        ' If you need more information about "HTML to RTF .Net" email us at:
        ' support[at]sautinsoft.com    
        ReplaceValuesInRtf()
    End Sub

    Public Sub ReplaceValuesInRtf()
        Dim h As New SautinSoft.HtmlToRtf()

        ' After purchasing the license, please insert your serial number here to activate the component.
        'h.Serial = "XXXXXXXXX"


        ' 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 = "..\footer.rtf"
        Dim wherewithReplaceRtfPath As String = "..\footer.rtf"
        Dim textToReplace As String = "sample"
        Dim resultRtfFile As String = Path.ChangeExtension(sourceRtfFile, ".result.rtf")

        h.MergeAndReplaceRtfFileFromFile(sourceRtfFile, textToReplace, wherewithReplaceRtfPath, resultRtfFile)

        ' Show the result.
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(resultRtfFile) With {.UseShellExecute = True})
    End Sub
End Module

See Also