• Post Reply Bookmark Topic Watch Topic
  • New Topic

looks like space but, very strange problem!  RSS feed

 
age spets
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
Have a strange problem. When I printout the charachter its empty " ", but when I do a regionMatches on that character it returns false. Have seen in my DB that the coding for this space is different than the normal coding hexadecimal=40 original now its 41. The problem comes up, when I update my database with data from a jsp. The data looks fine in the DB with spaces, it also goes fine in jsp before I do my formatting(with the space check), since it doesn't recognice the spaces. When exporting the data to pdf it removes all the spaces.. What can the problem be, and how can I fix it?
regards Age
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hex(40) = dec (64) = char ('6') on my system.
Since the character looks like a blank it needen't be a blank.
It might be a tab '\t' = dec (9) or it might be more than one space, a vertical tab or another character which isn't printable or isn't printable with your fonts.
Can you get it as byte, print as int and proove if it isn't more than one space? And explain why hex(41) or hex(40) is a space in the database?
 
age spets
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yepp, good points you had there. Now I have figured out what the problem was, and how it came. The hex value for space is 20 and my char had hex A0, you can use this code to convert:
/** Converts the given array of bytes to a hex String */
private static String toHex(byte[] buf)
{
char[] cbf = new char[buf.length * 2];
for (int jj = 0, kk = 0; jj < buf.length; jj++)
{
cbf[kk++] = "0123456789ABCDEF".charAt((buf[jj] >> 4) & 0x0F);
cbf[kk++] = "0123456789ABCDEF".charAt(buf[jj] & 0x0F);
}
return new String(cbf);
}
The problem started when I formatet the adress from the DB call, since the text behind the first "space" didnt show, I formated the "space" to " " and then you could see the rest of the field on the web. This error came up, since I forgot to use ' ' outside the String. Didn't know you had to do that to show the complete string. Then I saved it like that to the DB... And the problem began.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!