Amy Raj
Amy Raj

Reputation: 21

RichTextbox, RTF in VB.NET

I am using richtextbox in vb.net , which contains the value "секция", which is russian word.

rtf1.selectedrtf and rtf.rtf, it returns /Un representation of characters. Is there any way or option in rtf to return the value in \uXXXX format?.

секция='f1\'e5\'ea\'f6\'e8\'ff 
секция=\u0441\u0435\u043A\u0446\u0438\u044F (<-- i need this format)
=============================
rtf1.text=секция
rtf1.selectedrtf returns
"{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset204{\*\fname Arial;}Arial CYR;}}  \uc1\pard\b\protect\f0\fs16\'f1\'e5\'ea\'f6\'e8\'ff}  "  

Upvotes: 2

Views: 3053

Answers (2)

Chung Xa
Chung Xa

Reputation: 31

I have a small function to convert a unicode string to unicode rtf text.

Private Function UnicodeStringToRtfText(str As String) As String
    Dim arrStr As Char() = str.ToCharArray()
    Dim retStr As String = ""
    For Each ch As String In arrStr
        If (AscW(ch) > 122) Then
            retStr &= "\u" & AscW(ch) & "?"
        Else
            retStr &= ch
        End If
    Next
    Return retStr
End Function

Hope this help!

Upvotes: 1

jacqijvv
jacqijvv

Reputation: 880

You can use the Encoding class found in System.Text to get the format in utf 8.

Eg:

Encoding.UTF8.GetBytes(RichTextBox1.Text)

For more details you can look at the following link at msdn:

Encoding.UTF8 Property It has good coding examples that you can follow. I did not find anyway to set the encoding for a richtextbox but you can using the encoding class to get the format that you desire.

Upvotes: 0

Related Questions