How to use Numeric Character Reference
in C# and VB.Net.
Complete code
using System;
using System.IO;
using System.Text;
namespace Sample
{
class sample
{
static void Main(string[] args)
{
string inpFile = @"..\..\unicode.rtf";
string outFileNCR = @"NCR.html";
string outFileNoNCR = @"Without NCR.html";
SautinSoft.RtfToHtml r = new SautinSoft.RtfToHtml();
try
{
r.OpenRtf(inpFile);
// Set to use NCR (Numeric Character Reference), in other words
// write characters as XXX;
r.UseNumericCharacterReference = true;
r.TextStyle.Title = "NCR";
r.ToHtml(outFileNCR);
// Don't use NCR, write characters us Unicode (utf-8), like a: på taket är en figur.
r.UseNumericCharacterReference = false;
r.TextStyle.Title = "Without NCR";
r.ToHtml(outFileNoNCR);
// Open the results for demonstration purposes.
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFileNCR)
{ UseShellExecute = true });
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFileNoNCR)
{ UseShellExecute = true });
}
catch (Exception e)
{
Console.WriteLine($"Error: {e.Message}");
Console.WriteLine("Press any key ...");
Console.ReadKey();
}
}
}
}
Imports System
Imports System.IO
Imports System.Text
Namespace Sample
Friend Class sample
Shared Sub Main(ByVal args() As String)
Dim inpFile As String = "..\..\unicode.rtf"
Dim outFileNCR As String = "NCR.html"
Dim outFileNoNCR As String = "Without NCR.html"
Dim r As New SautinSoft.RtfToHtml()
Try
r.OpenRtf(inpFile)
' Set to use NCR (Numeric Character Reference), in other words
' write characters as XXX;
r.UseNumericCharacterReference = True
r.TextStyle.Title = "NCR"
r.ToHtml(outFileNCR)
' Don't use NCR, write characters us Unicode (utf-8), like a: på taket är en figur.
r.UseNumericCharacterReference = False
r.TextStyle.Title = "Without NCR"
r.ToHtml(outFileNoNCR)
' Open the results for demonstration purposes.
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outFileNCR) With {.UseShellExecute = True})
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outFileNoNCR) With {.UseShellExecute = True})
Catch e As Exception
Console.WriteLine($"Error: {e.Message}")
Console.WriteLine("Press any key ...")
Console.ReadKey()
End Try
End Sub
End Class
End Namespace
If you are looking also for a .Net solution to Create or Modify HTML documents, see our Document .Net.
If you need a new code example or have a question: email us at support@sautinsoft.com or ask at Online Chat (right-bottom corner of this page) or use the Form below: