Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > String to character literal conversion

Reply
Thread Tools

String to character literal conversion

 
 
-D
Guest
Posts: n/a
 
      09-04-2004
Hi all,

How do you evaluate a string as unicode literal? That is,
how do you convert "\u004E" (normal string) to '\u004E' (character literal)?

Thanks!

- D
 
Reply With Quote
 
 
 
 
Alan Moore
Guest
Posts: n/a
 
      09-04-2004
On 3 Sep 2004 17:41:02 -0700, http://www.velocityreviews.com/forums/(E-Mail Removed) (-D) wrote:

>Hi all,
>
>How do you evaluate a string as unicode literal? That is,
>how do you convert "\u004E" (normal string) to '\u004E' (character literal)?
>


char ch = (char)Integer.parseInt("\\u004E".substring(2), 16);

 
Reply With Quote
 
 
 
 
Tor Iver Wilhelmsen
Guest
Posts: n/a
 
      09-04-2004
(E-Mail Removed) (-D) writes:

> How do you evaluate a string as unicode literal? That is,
> how do you convert "\u004E" (normal string) to '\u004E' (character literal)?


If it's in source code, the resulting String will have 1 character;
you get that with

char ch = theString.charAt(0);
 
Reply With Quote
 
Thomas Schodt
Guest
Posts: n/a
 
      09-04-2004
-D wrote:

> How do you evaluate a string as unicode literal? That is,
> how do you convert "\u004E" (normal string) to '\u004E' (character literal)?


The only way I can make any sense of your post is if you mean


public class Eval {
// note the double backslash
static final String normalString = "\\u004E";
static final char literalCharacter = evaluateString(normalString);

// argument must contain "\\uXXXX" exactly
// first is a backslash '\\', second is a lowercase 'u'
// ande XXXX is a unicode character id
static char evaluateString(String s) {
// insert code here
return (char)Integer.parseInt(s.substring(2),0x10);
}

public static void main(String[] arg) {
System.out.println(literalCharacter);
}
}


Improving the evaluateString() to take arguments of varying format
is left as an exercise for the OP.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Initializing a character array with a string literal? Jef Driesen C Programming 15 03-26-2010 07:40 PM
Initializing a character array with a string literal? Jef Driesen C++ 9 03-26-2010 07:40 PM
8 bit character string to 16 bit character string Brand Bogard C Programming 8 05-28-2006 05:05 PM
Insert a new line character into a string literal Water Cooler v2 Javascript 4 04-18-2006 12:02 PM
What's wrong with rpc-literal? Why use doc-literal? Anonieko Ramos ASP .Net Web Services 0 09-27-2004 09:06 AM



Advertisments