[android-developers] Re: Why String \0 is converted to [65533,65533]

2009-11-16 Thread fadden
On Nov 14, 5:58 am, Joes joyj...@gmail.com wrote:
 While I'm programming the Android SMTP code,I met a confused problem
 with code similar as the following:
     String str= \0 username \0 passwrd;
 After executed the code, I found \0 is intepreted as two
 undisplayable char.

I ran a quick test and saw (as others have) that this returns a single-
character string with one character (0), as expected.

(Stretching) if you converted the string to a UTF-8 byte array, you
would see two bytes (0xc0 0x80) due to the way that Java specifies its
modified UTF-8; see e.g. 
http://java.sun.com/javase/6/docs/technotes/guides/jni/spec/types.html#wp16542
.  However, I don't see how you would get to something like 65533 (-3)
from there.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Why String \0 is converted to [65533,65533]

2009-11-15 Thread PJ
I assume that this is Java code and not C code.  Is that right?

Are you sure that you posted your code correctly?  When I try what
you've done, I get an IndexOutOfBoundsException when executing
sZero.charAt(1), which is what I would expect.

Also, are you sure you're getting 65533 and not 65535?  If you convert
a value of -1 to an unsigned 16-bit integer, you get 65535.  If you
don't understand why, search the web for how negative integers are
stored at the bit level.  So, this might be related.

Also, it sounds like you want to control things at the byte level.  If
so, you probably want to use the byte data type and stay away from
char and int and String.  Don't think of a String as an array of
bytes, because it's not (in Java).  It's more list a list of
characters WHERE each character might actually take up more than
one byte because of internationalization support.

So perhaps you should be working with byte instead of char,
assuming you're trying to manipulate things at the byte level.

-- PJ



On Nov 14, 9:42 am, Joes joyj...@gmail.com wrote:
 I just wanna know, with what condition can cause this issue.  I think
 it's probably because of the charset setup which is controlled by
 makefile or something else. I need a direction to look into.

 Thanks

 On Nov 14, 9:18 am, Andrei gml...@gmail.com wrote:



  just a guess that u want to do this instead \\0

  On Nov 14, 8:58 am, Joes joyj...@gmail.com wrote:

   All,
   While I'm programming the Android SMTP code,I met a confused problem
   with code similar as the following:
       String str= \0 username \0 passwrd;
   After executed the code, I found \0 is intepreted as two
   undisplayable char.
   Then I executed the folloing debug code:
       String sZero = \0;
       int iLen = sZero.length();
       int iValue1 = (int)sZero.charAt(0);
       int iValue2 = (int)sZero.charAt(1);
       Log.w(ZERO, Zero String, Lenth=, iLen,  value1=, iValue1, 
   value2=, iValue2);
   What I get in screen is :
       Zero String, Length=2 value1=65533 value2=65533.

   Really confuse me, why \0 become [65533,65533] in my program?

   Thanks- Hide quoted text -

  - Show quoted text -

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Why String \0 is converted to [65533,65533]

2009-11-14 Thread Andrei
just a guess that u want to do this instead \\0

On Nov 14, 8:58 am, Joes joyj...@gmail.com wrote:
 All,
 While I'm programming the Android SMTP code,I met a confused problem
 with code similar as the following:
     String str= \0 username \0 passwrd;
 After executed the code, I found \0 is intepreted as two
 undisplayable char.
 Then I executed the folloing debug code:
     String sZero = \0;
     int iLen = sZero.length();
     int iValue1 = (int)sZero.charAt(0);
     int iValue2 = (int)sZero.charAt(1);
     Log.w(ZERO, Zero String, Lenth=, iLen,  value1=, iValue1, 
 value2=, iValue2);
 What I get in screen is :
     Zero String, Length=2 value1=65533 value2=65533.

 Really confuse me, why \0 become [65533,65533] in my program?

 Thanks

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Why String \0 is converted to [65533,65533]

2009-11-14 Thread Joes
I just wanna know, with what condition can cause this issue.  I think
it's probably because of the charset setup which is controlled by
makefile or something else. I need a direction to look into.

Thanks


On Nov 14, 9:18 am, Andrei gml...@gmail.com wrote:
 just a guess that u want to do this instead \\0

 On Nov 14, 8:58 am, Joes joyj...@gmail.com wrote:



  All,
  While I'm programming the Android SMTP code,I met a confused problem
  with code similar as the following:
      String str= \0 username \0 passwrd;
  After executed the code, I found \0 is intepreted as two
  undisplayable char.
  Then I executed the folloing debug code:
      String sZero = \0;
      int iLen = sZero.length();
      int iValue1 = (int)sZero.charAt(0);
      int iValue2 = (int)sZero.charAt(1);
      Log.w(ZERO, Zero String, Lenth=, iLen,  value1=, iValue1, 
  value2=, iValue2);
  What I get in screen is :
      Zero String, Length=2 value1=65533 value2=65533.

  Really confuse me, why \0 become [65533,65533] in my program?

  Thanks- Hide quoted text -

 - Show quoted text -

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en