| Author |
I know this sounds crazy
|
jesse harris
Ranch Hand
Joined: Oct 02, 2000
Posts: 62
|
|
I know this sounds crazy, but i am a scjp and I cant seem to find a way to remove a char from a string or stringbuffer, my docs tell me that java 2 has a stringbuffer method deleteCharAt(int x) but I am using 1.8.1 and cant seem to get it done. this is really embarrasing, any help appreciated jesse
|
 |
Carl Trusiak
Sheriff
Joined: Jun 13, 2000
Posts: 3340
|
|
Then you obviously know the location of the character in the string. Add the substrings everything before it and everything after it. This prints out "Hello Carl" ------------------ Hope This Helps Carl Trusiak, SCJP2
|
I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
|
 |
jesse harris
Ranch Hand
Joined: Oct 02, 2000
Posts: 62
|
|
I have thought of that but isn't there a more elegant way to do it why isn't there a metheod to do it?
|
 |
Carl Trusiak
Sheriff
Joined: Jun 13, 2000
Posts: 3340
|
|
Well, StringBuffer in JDK1.3 uses the following method This may work in 1.8.1 but, I'm not sure. The method signiture in System is public static void arraycopy(Object src, int src_position, Object dst, int dst_position, int length) System uses a native call for this so.....
|
 |
jesse harris
Ranch Hand
Joined: Oct 02, 2000
Posts: 62
|
|
wow that seems cheesy too any of you studs know why there isn't a removeCharAt() or deleteCharAt() in the stringbuffer class. There must be a reason that this is such a shaky topic. I can somewhat understand the lacking of this in the String class due to their immutability, but the StringBuffer class isn't bound by those same rules. Any thoughts from the gurus? jesse
|
 |
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18670
|
|
|
The deleteCharAt() method does exist in Java 1.2 and onwards, but it was omitted from earlier versions. See the line in the javadoc, "Since: 1.2"? That's how they indicate when a method was added to the API. Evidently there was no elegant way of doing this in the earlier Java releases; that's why they added the method later (along with several others). Sun released a lot of stuff in a short time for Java; mistakes were made along the way. Where possible, they were usually corrected later, as in this case.
|
"I'm not back." - Bill Harding, Twister
|
 |
jesse harris
Ranch Hand
Joined: Oct 02, 2000
Posts: 62
|
|
|
thanks a lot jim
|
 |
 |
|
|
subject: I know this sounds crazy
|
|
|