473,659 Members | 3,082 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

unicode to character

This is a Chinese character in unicode: 挪
I made it in Javascript by adding "&#"+"25"+" 386"
I need to convert it in Javascript to this: 挪 (The actual character)
How do I achieve this conversion in Javascript?

Jas

Jan 26 '07 #1
4 2729
Hi Jason.

Jason wrote:
This is a Chinese character in unicode: 挪
I made it in Javascript by adding "&#"+"25"+" 386"
I need to convert it in Javascript to this: 挪 (The actual character)
How do I achieve this conversion in Javascript?
挪 isn't the character in Unicode, it's the numeric character
entity in XML and HTML that means that character. 25386 is the Unicode
codepoint of that character. You can use the String.fromChar Code
function to create a string with a single character, given the codepoint.

If you have the codepoint, just pass it to the function. If you have
the string "挪", you need to extract the number from the string
and then pass it to the function. You can use something like:

function numericEntityTo Char(s) {
return String.fromChar Code(s.match(/^&#(\d+);$/)[1]);
}

If you have a numeric character entity that uses hexadecimal, you'll
have to do it differently, e.g.:

function numericEntityTo Char(s) {
var xs = s.match(/^&#(x[0-9A-Fa-z]+);$/));
if (xs) {
return Number('0' + xs[1]);
}
return Number(s.match(/^&#(\d+);$/)[1]);
}

(Completely untested code, though.)

--
Cameron McCormack, http://mcc.id.au/
xmpp:he****@jab ber.org â–ª ICQ 26955922 â–ª MSN ca*@mcc.id.au
Jan 26 '07 #2
Couldn't get it working. Here is a test page:

http://dheera.net/jason/test.html

Jas

On Jan 26, 2:49Â*pm, Cameron McCormack <c...@mcc.id.au wrote:
Hi Jason.

Jason wrote:
This is a Chinese character inunicode: 挪
I made it in Javascript by adding "&#"+"25"+" 386"
I need to convert it in Javascript to this: 挪 (The actual character)
How do I achieve this conversion in Javascript?挪 isn't the character inUnicode, it's the numeric character
entity in XML and HTML that means that character. Â*25386 is theUnicode
codepoint of that character. Â*You can use the String.fromChar Code
function to create a string with a single character, given the codepoint.

If you have the codepoint, just pass it to the function. Â*If you have
the string "挪", you need to extract the number from the string
and then pass it to the function. Â*You can use something like:

Â* function numericEntityTo Char(s) {
Â* Â* return String.fromChar Code(s.match(/^&#(\d+);$/)[1]);
Â* }

If you have a numeric character entity that uses hexadecimal, you'll
have to do it differently, e.g.:

Â* function numericEntityTo Char(s) {
Â* Â* var xs = s.match(/^&#(x[0-9A-Fa-z]+);$/));
Â* Â* if (xs) {
Â* Â* Â* return Number('0' + xs[1]);
Â* Â* }
Â* Â* return Number(s.match(/^&#(\d+);$/)[1]);
Â* }

(Completely untested code, though.)

--
Cameron McCormack,http://mcc.id.au/
Â* Â* Â* Â* xmpp:hey...@jab ber.org Â*â–ª Â*ICQ 26955922 Â*â–ª Â*MSN c...@mcc.id.au
Jan 27 '07 #3
Jason <ja*******@gmai l.comwrote:
On Jan 26, 2:49Â*pm, Cameron McCormack <c...@mcc.id.au wrote:
If you have the codepoint, just pass it to the function.
If you have the string "挪", you need to extract
the number from the string and then pass it to the function.
You can use something like:
function numericEntityTo Char(s) {
return String.fromChar Code(s.match(/^&#(\d+);$/)[1]);
}
Couldn't get it working. Here is a test page:
http://dheera.net/jason/test.html
try :
<script type="text/javascript">
//<![CDATA[
function numericEntityTo Cha(s) {
return String.fromChar Code(s.match(/^&#(\d+);$/ )[1] );
}

function numericEntityTo Char(s) {
var xs = s.match(/^&#(x[0-9A-Fa-z]+);$/ );
if (xs) {
return Number('0' + xs[1] );
}
return Number(s.match(/^&#(\d+);$/ )[1] );
}

document.write( numericEntityTo Cha('挤' ) );
document.write( numericEntityTo Char('挤' ) );
document.write( "asd" );
//]]>
</script>
--
@@@@@
E -00 comme on est very beaux dis !
' `) /
|\_ =="
Jan 27 '07 #4
Cameron, Denisb thanks so much for your help. Much appreciated. :)

Jas

On Jan 27, 7:29 pm, n...@no-log.org (denisb) wrote:
Jason <jasonr...@gmai l.comwrote:
On Jan 26, 2:49 pm, Cameron McCormack <c...@mcc.id.au wrote:
If you have the codepoint, just pass it to the function.
If you have the string "挪", you need to extract
the number from the string and then pass it to the function.
You can use something like:
function numericEntityTo Char(s) {
return String.fromChar Code(s.match(/^&#(\d+);$/)[1]);
}
Couldn't get it working. Here is a test page:
http://dheera.net/jason/test.htmltry :
<script type="text/javascript">
//<![CDATA[
function numericEntityTo Cha(s) {
return String.fromChar Code(s.match(/^&#(\d+);$/ )[1] );

}function numericEntityTo Char(s) {
var xs = s.match(/^&#(x[0-9A-Fa-z]+);$/ );
if (xs) {
return Number('0' + xs[1] );
}
return Number(s.match(/^&#(\d+);$/ )[1] );

}document.write (numericEntityT oCha('挤' ) );
document.write( numericEntityTo Char('挤' ) );
document.write( "asd" );
//]]>
</script>

--
@@@@@
E -00 comme on est very beaux dis !
' `) /
|\_ =="
Jan 27 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
25923
by: Hallvard B Furuseth | last post by:
Has someone got a Python routine or module which converts Unicode strings to lowercase (or uppercase)? What I actually need to do is to compare a number of strings in a case-insensitive manner, so I assume it's simplest to convert to lower/upper first. Possibly all strings will be from the latin-1 character set, so I could convert to 8-bit latin-1, map to lowercase, and convert back, but that seems rather cumbersome.
14
2837
by: wolfgang haefelinger | last post by:
Hi, I wonder whether someone could explain me a bit what's going on here: import sys # I'm running Mandrake 1o and Windows XP. print sys.version ## 2.3.3 (#2, Feb 17 2004, 11:45:40)
27
5139
by: EU citizen | last post by:
Do web pages have to be created in unicode in order to use UTF-8 encoding? If so, can anyone name a free application which I can use under Windows 98 to create web pages?
6
2777
by: S. | last post by:
if in my website i am using the sgml { notation, is it accurate to say to my users that the site uses unicode or that it requires unicode? is there a mathematical formula to calculate a unicode value given its utf8 value? Rgds, Sam
48
4619
by: Zenobia | last post by:
Recently I was editing a document in GoLive 6. I like GoLive because it has some nice features such as: * rewrite source code * check syntax * global search & replace (through several files at once) * regular expression search & replace. Normally my documents are encoded with the ISO setting. Recently I was writing an XHTML document. After changing the encoding to UTF-8 I used the
4
3161
by: Basil | last post by:
Hello. I have compiler BC Builder 6.0. I have an example: #include <strstrea.h> int main () { wchar_t ff = {' s','d ', 'f', 'g', 't'};
13
3296
by: Tomás | last post by:
Let's start off with: class Nation { public: virtual const char* GetName() const = 0; } class Norway : public Nation { public: virtual const char* GetName() const
12
3028
by: damjan | last post by:
This may look like a silly question to someone, but the more I try to understand Unicode the more lost I feel. To say that I am not a beginner C++ programmer, only had no need to delve into character encoding intricacies before. In c/c++, the unicode characters are introduced by the means of wchar_t type. Based on the presence of _UNICODE definition C functions are macro'd to either the normal version or the one prefixed with w. Because...
1
4844
by: jrs_14618 | last post by:
Hello All, This post is essentially a reply a previous post/thread here on this mailing.database.myodbc group titled: MySQL 4.0, FULL-TEXT Indexing and Search Arabic Data, Unicode I was wondering if anybody has experienced the same issues
7
4016
by: 7stud | last post by:
Based on this example and the error: ----- u_str = u"abc\u9999" print u_str UnicodeEncodeError: 'ascii' codec can't encode character u'\u9999' in position 3: ordinal not in range(128) ------
0
8335
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8528
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8627
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6179
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2752
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1976
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.