encoding - How do I display a Registered Trademark symbol (®) using VB.NET? -
i have taken on support of application @ company work for. of sudden, customer wants able enter registered trademark in name field. symbol, using alt+0174, being saved correctly, app not encoding properly. i'm doing:
private sub btnsave_click(byval sender system.object, byval e system.eventargs) handles btnsave.click dim ms new memorystream dim xml_text_writer new xmltextwriter(ms, _ system.text.encoding.utf8) xml_text_writer.formatting = formatting.indented xml_text_writer.indentation = 4 xml_text_writer.writestartdocument(true) xml_text_writer.writestartelement("employees") makeemployee(xml_text_writer, txtfname.text, txtlname.text, 11111) xml_text_writer.writeendelement() xml_text_writer.writeenddocument() xml_text_writer.flush() ms.flush() ms.position = 0 dim b(cint(ms.length) - 1) byte ms.read(b, 0, cint(ms.length)) ms.close() dim strreturn string = system.text.asciiencoding.ascii.getstring(b) if strreturn.startswith("???", stringcomparison.currentcultureignorecase) strreturn = strreturn.substring(3) end if txtname.text = strreturn end sub private sub makeemployee(byval xml_text_writer _ xmltextwriter, byval first_name string, byval _ last_name string, byval emp_id integer) xml_text_writer.writestartelement("employee") xml_text_writer.writestartelement("firstname") xml_text_writer.writestring(first_name) xml_text_writer.writeendelement() xml_text_writer.writestartelement("lastname") xml_text_writer.writestring(last_name) xml_text_writer.writeendelement() xml_text_writer.writestartelement("employeeid") xml_text_writer.writestring(emp_id.tostring) xml_text_writer.writeendelement() xml_text_writer.writeendelement() end sub
the output code this:
john smith ?? 11111
everything fine, except "??" after "smith" should "®". best way, if any, display symbol correctly?
dim strreturn string = system.text.asciiencoding.ascii.getstring(b)
you encoded xml in utf-8, don't read ascii. you'll lose special characters cannot encoded. fix:
dim strreturn string = system.text.encoding.utf8.getstring(b)
Comments
Post a Comment