String contains a square symbol ???

J

james.fitzjohn

Ive sent some data via asocket to another app and when it returns the
data it contains two [][] squares at the start. how can I get rid of
these squares i thought they might be \r or \n's but there not
 
T

Thomas Weidenfeller

Ive sent some data via asocket to another app and when it returns the
data it contains two [][] squares at the start.

No, it doesn't. The data just contains numbers in the form of bits and
bytes. It is a matter of interpretation how these numbers are visually
represented. Most likely you try to print the data as-is, and the
current font has no glyph for the corresponding codes. In such a case
Java happens to print squares. But there are no squares in the data - it
is just that Java decides to represent the particular numbers as squares
for lack of a better representation.
how can I get rid of
these squares i thought they might be \r or \n's but there not

Maybe they are. Get a debugger and look at them. Or use a print
statement to print out the codes (not the glyphs, but the numbers). Or
use a network sniffer like ethereal to verify that you indeed have the
data one the wire which you think you have.

/Thomas
 
T

Tim Ward

Thomas Weidenfeller said:
Ive sent some data via asocket to another app and when it returns the
data it contains two [][] squares at the start.

No, it doesn't. The data just contains numbers in the form of bits and
bytes. It is a matter of interpretation how these numbers are visually
represented. Most likely you try to print the data as-is, and the
current font has no glyph for the corresponding codes. In such a case
Java happens to print squares. But there are no squares in the data - it
is just that Java decides to represent the particular numbers as squares
for lack of a better representation.

Could this be a BOM? - I'd have thought, however, that any Jave Unicode
streaming stuff that he might be using would have known how to deal with
that.
 
J

james.fitzjohn

Yes I was sure that they were some sort of undisplayable character such
as a tab or lf, but how do I get rid off them?


Im sure the other app isnt sending those characters
 
T

Tim Ward

Yes I was sure that they were some sort of undisplayable character such
as a tab or lf, but how do I get rid off them?

Im sure the other app isnt sending those characters

How are you sure? You've sniffed the traffic on the wire?
 
T

Thomas Weidenfeller

Tim said:
Could this be a BOM?

That's for sure possible, yes, but how could we know? All we know is
that the OP reads from a socket, but we don't know how it is read. We
also don't know how the data was written (text or binary) at the other end.

We both suggested to sniff the traffic, and that is IMHO the most
sensible way to start.
- I'd have thought, however, that any Jave Unicode
streaming stuff that he might be using would have known how to deal with
that.

That is definitely not the case. See

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4508058

Someone has even copied workaround code from an old discussion in this
group into the bug report. Still after four years Sun hasn't fixed this.

/Thomas
 
M

Mike Schilling

Tim Ward said:
Thomas Weidenfeller said:
Ive sent some data via asocket to another app and when it returns the
data it contains two [][] squares at the start.

No, it doesn't. The data just contains numbers in the form of bits and
bytes. It is a matter of interpretation how these numbers are visually
represented. Most likely you try to print the data as-is, and the
current font has no glyph for the corresponding codes. In such a case
Java happens to print squares. But there are no squares in the data - it
is just that Java decides to represent the particular numbers as squares
for lack of a better representation.

Could this be a BOM? - I'd have thought, however, that any Jave Unicode
streaming stuff that he might be using would have known how to deal with
that.

Maybe not. Microsoft sometimes uses a BOM to announce "UTF-8 follows";
that's non-standard and Java won't interpret it as such. (Though their
UTF-8 BOM is three bytes.)
 
R

Roedy Green

Ive sent some data via asocket to another app and when it returns the
data it contains two [][] squares at the start. how can I get rid of
these squares i thought they might be \r or \n's but there not

Most likely those two squares are the unicode byte order marks. You
simply have to notice them and not try to display them.

See http://mindprod.com/jgloss/unicode.html for an explanation.

see also http://mindprod.com/jgloss/encoding.html

--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
J

james.fitzjohn

Thanks for the help guys, the server was sending a \r\n and the java
string didnt know what to do with it
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top