Hi Friends,

I want to convert given String of any language to Unicode.Please solve my porblem friends.

Thank you

cheers
--------
siva

Hi friend,
Thank you for your reply,but my problem is that i want to accept the String in any language
and to display the unicode of this String.But this url can't solve my problem.Please give alternate solution friend.

Thank you

Cheers
-------
Siva

tried Google yet?
http://www.java2s.com/Code/Java/Development-Class/StringConverterUnicode.htm

commented: Then do some research on your own or provide some of your code and explain what it wrong. -2

Give a sample of what you want ??
We cant dream up things you know !!!

I checked out the link, and the code seems to do what you want.

What code have you tried? What problems are occurring with it? Have you studied the Sun tutorials and the APIs related to this code?

"Please solve my porblem friends"(sic) doesn't show any effort on your part.

Hi Friends,

I want to convert given String of any language to Unicode.Please solve my porblem friends.

Thank you

cheers
--------
siva

Try this. Looks like proper tabbing is not supported her, but I think you can figure it out.

/**
	 * Method convert(String str)
	 * Implemented as a class method.
	 * 
	 * Takes one argument: a string that may contain international characters.
	 * Returns: a string with the international characters converted to hex-encoded unicode.
	 * A hex-encoded unicode character has this format: \ u x x x x (spaces added for emphasis)
	 * where xxxx is the hex-encoded value of the character. The xxxx part is
	 * always 4 digits, 0 filled to make 4 digits.
	 * 
	 * Example input/output:
	 * 		Input string:   Constitución
	 * 		Encoded output: Constituci\u00f3n
	 * 
	 * Example call: String term = unicodeString.convert("Constitución"); 
	 */

import java.util.Locale;

public class unicodeString
{
	public static String convert(String str)
	{
		StringBuffer ostr = new StringBuffer();

		for(int i=0; i<str.length(); i++) 
		{
			char ch = str.charAt(i);

			if ((ch >= 0x0020) && (ch <= 0x007e))	// Does the char need to be converted to unicode? 
			{
				ostr.append(ch);					// No.
			} else 									// Yes.
			{
	        	ostr.append("\\u") ;				// standard unicode format.
				String hex = Integer.toHexString(str.charAt(i) & 0xFFFF);	// Get hex value of the char. 
				for(int j=0; j<4-hex.length(); j++)	// Prepend zeros because unicode requires 4 digits
					ostr.append("0");
				ostr.append(hex.toLowerCase());		// standard unicode format.
				//ostr.append(hex.toLowerCase(Locale.ENGLISH));
			}
		}

	return (new String(ostr));		//Return the stringbuffer cast as a string.

	}

dcinminn

Thanks I just stumbled on this and it solves my problem beautifully
pitty that people dont bother thanking others for their work

Greg

dcinminn

Thanks I just stumbled on this and it solves my problem beautifully
pitty that people dont bother thanking others for their work

Greg

Would be down to the fact that solution was provided 6 months after initial request when people either solve it on their own or already forgot and move on with other stuff

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.