Manning's Countdown to 2014
. Use discount code crdotd14 all month for 50% off every deal.
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
subject: using replace() method
replacee / with \
Replace all "." in a string
Removing specific character from the given String
How to remove '\0'
ereg_replace aka regexp in jsp
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013