Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hello, I have to import text wit

Status
Not open for further replies.

goaganesha

Programmer
Dec 4, 2001
178
BE
Hello,

I have to import text with special characters like ë from a mysql database. I want to test the string, in which I put the text, for these special characters but somehow these characters seem to be converted to a question mark before I have the chance to test for them. The special characters are never found and a questionmark is replacing them when i display them in the console window.

For testing I've put an ë in the database.
this is the method that i'm using:
Code:
public String convertPlainToHtml(String input) 
{
 System.out.println("================="+input);
 if (input.trim().indexOf('ë',0) != -1)
 {
 System.out.println("found one");
 String temp="ë";
 String html="euml";
 input.replaceAll(temp,html);
 }
 else
 {
 System.out.println("not found");
 }
 return input;
 }
 

 
 This is the console output I get:
 
 ================?
 not found
I also replaced the ë with \u00eb and it gives the same result.

Any suggestions?

regards, goaganesha
 
Probably a good thing to do right now is to directly test a word containing an 'ë', without taking it from the database. This is: or as an argument of the main method, or by declarating a local variable with the word.

That way you will eliminate the possibility of the problem occuring at the database side.
 
Thank you for your reply,
I don't think the problem occurs at the database side 'cause I converted the input to it's hexvalue and the result is ffeb.

The only problem I now have is how to test for the presence of a hexvalue ffeb.

regards, goaganesha
 
Java operates in Unicode, which your database may not, so the value in your database which makes up that char may be different for the Unicode. I've noticed a ñ in an ansi file is like a +- but combined in one char.
 
thanks for your reply.

I finally got the problem solved. Here is the code if someone else might be having this problem.
To know what the hexvalue of the input from the database is use this code:
Code:
public class StringToHex
{
  public static void convert(String input)
  {
    System.out.println("String INPUT is:  " + input);
    char[] letter = input.toCharArray();

    for (int j = 0; j <letter.length; j++)
    {
    String hexValue = Integer.toHexString(letter[j]);
    System.out.print(hexValue + &quot;--&quot;);
    }
  }
}[\code]

Then the conversion is done using this code (example for ë)
[code]
public class ConvertInput
{
    public static String convert(String input)
    {
    
    System.out.println(&quot;String input = &quot; + input);
    String conv= input.replaceAll(&quot;\\uffeb&quot;, &quot;\u00eb&quot;);
    System.out.println(&quot;String conv= &quot; + conv);
    return conv;
    }


}[\code]


Special thanks to ChuckBing for helping me.
regards, goaganesha
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top