Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes String method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String method" Watch "String method" New topic
Author

String method

Qusay Jaafar
Ranch Hand

Joined: May 06, 2002
Posts: 127
Hi,
1- How can I convert a deprecated String constructor which is:
String(byte[] ascii, int hibyte, int offset, int count)
to another non-deprecated String constructor?
2- How can I convert a deprecated String method which is:
getBytes(int srcBegin, int srcEnd, byte[] dst, int dstBegin)
to another non-deprecated String method?
I appreciate if your explination with a code
Regards
Q. Jaafar


Qusay
Max Habibi
town drunk
( and author)
Sheriff

Joined: Jun 27, 2002
Posts: 4118
Jaffer,
1. If this is for the developer certification, then this question should probably be asked in the developer's forum.
2. IMO, this is the sort of thing you should look up. It will only take about five minutes to figure out.
M


Java Regular Expressions
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
1. (To Max) Well, maybe. But at this point, it's been asked in a bunch of other forums as well, and others have already chosen to redirect some of the other forums here, so I'd choosing to answer it here for consistency.
(To Quasi) If the value of hibyte used was 0, then the simplest solution is to use the String(byte[], int, int, int) constructor instead:
new String(ascii, offset, count, "ISO-8859-1")
since ISO-8859-1 directly Unicode encoding for values 0-0xFF. Also worth trying is
new String(ascii, offset, count)
since it's reasonably possible the original code simply meant to use the platform default encoding, but didn't get it quite right. This typically makes little difference for "normal" ascii values - but look for funny chars like ™ and ‰ (if they are used anywhere) to see if they're coming out OK or not.
If the value of hibyte is anything other than 0, read the code very carefully and try to determine the author's actual intent. Consider the possibility that they were on crack at the time, and their decoding method may simply be fundamentally wrong. Was there some standard named encoding scheme they were trying to replicate? If so, it might be better to learn the name of the encoding, and use one of the String constructors that accepts a named encoding. If it's really necessary to replicate the original functionality exactly, you can read the description for the deprecated method carefully, and write your own code which creates a char[] array and populates it with chars created from the byte[] array as described (taking hibyte into account). Then use one of the non-deprecated constructors to make a String from the char[].
2. Generally, the answer to this question is probably based on the answer to 1. Whichever constructor/encoding combination turns out to work best above, there's a corresponging getBytes() method which can reverse the process.
[ July 17, 2002: Message edited by: Jim Yingst ]

"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String method
 
Similar Threads
Deprecated Methods ?
NX:About deprecated methods
String method
String method
Quick String to <char> Array Conversion