Click here to Skip to main content
15,885,954 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
so I am working on a program where I download text from a website and all characters that are unicode comes up, for example, so here \u00f6 and in my vb.net code do they show up as \u00f6 but I want the unicode character show up as "ö" and but I did not manage to convert the unicode to them real characters and I wonder if anyone can help me convert unicode characters to the letters I can see in my Textbox

i have search on google and the only result i can find is "how to convert character to unicode"
Posted

VB.NET doesn't have escape sequences for that stuff.

You have a couple of solutions and they're both pretty easy.

1) Open CharMap, find the character you're looking for and click on it, then the Select button. Click the Copy button and you can paste it directly into the string in your code.

2) You can use the ChrW function to return the character and insert it into your string:
Dim myString As String
myString = "This is a test of inserting a " & ChrW(&HF6) & " character in a string."
 
Share this answer
 
v2
Comments
Shahan Ayyub 4-Apr-14 12:43pm    
There is no function `CharW`. Use `ChrW` instead that you are recommending to others. I would prefer just leaving a comment next time if i think answer can be improve, because i think it can be of more helpful rather than mandatory downvoting.
Dave Kreskowiak 4-Apr-14 18:45pm    
Whoops, typo! Fixed.
In your test case `\u00f6`:

`\u` = It is a unicode character.
`00f6` = Hexadecimal representation

So you need to have its hexadecimal equivalent only. So try like this:

Code:
VB
Dim unicodeCharsString as string = "Today, I figured out how to convert `\u00F6` character to its character `" & Chr(Convert.ToInt32("00F6", 16)) & "` equivalent"


Output:

Today, I figured out how to convert `\u00F6` character to its character `ö` equivalent


Here:

Convert.ToInt32("00F6", 16)  '' convert hexadecimal to decimal representation
Chr()                        '' converts decimal representation to its equivalent character.
 
Share this answer
 
v2
Comments
Dave Kreskowiak 4-Apr-14 0:36am    
You don't need the Convert.ToInt32. You also don't need to specify the hex value as a string.

And Chr() doesn't work with values over 255, meaning it will not work with most Unicode characters. The proper function to use is ChrW().

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900