File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
using replace() method
Joined: Mar 15, 2000
Oct 25, 2001 12:48:00
I have a
str = "12345678";
Can anyone tell me why :
str.replace('4', 'B'); will give me "123B5678"
str.replace((char)4, 'B'); won't change str.
replace() requires a char parameter and I can't see anything wrong with casting an int to char.
Thanks for any help!
Joined: Sep 22, 2001
Oct 25, 2001 13:39:00
because (char)4 is not '4'.
Try this code -
System.out.println((char)4); //doesn't print 4
replace() method can't find character with unicode value 4 in the sting.
Joined: Oct 16, 2001
Oct 26, 2001 21:46:00
yes and replace('4','B'), will search for char '4' not for ((char)4) as they've diff values and then if found then replace it with 'B'. hope i helped
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
subject: using replace() method
Removing specific character from the given String
replacee / with \
ereg_replace aka regexp in jsp
How to remove '\0'
Replace all "." in a string
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015