Re: Java Replacing characters

  • From: "Gilbert Neiva" <gneiva@xxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Wed, 28 Jul 2010 17:59:02 -0600

Never mind. I figured it out. There is a method called replace that is 
associated with the string class. Here is how to use it.

String word1 = "cot";
System.out.println(word1);
word1 = word1.replace("o", "a");
System.out.println(word1);

Anyone who has trouble with this issue, just put together this little program 
and see what happens. Best of all, I didn't get this from a textbook. I figured 
it all on my own by looking up the verrious methods for class string and 
experimenting. Now all I need to do is learn how to replace characters in 
specific positions within a string verriable.

Gilbert Neiva

  ----- Original Message ----- 
  From: Gilbert Neiva 
  To: programmingblind@xxxxxxxxxxxxx 
  Sent: Wednesday, July 28, 2010 5:13 PM
  Subject: Java Replacing characters


  How do I replace a character in a string varriable with another.

  string word1;
  word1 = "cot"

  How would I for example replace the o with an a. I know that the method 
charAt() can be used to extract a character from a group of characters within a 
string. I know that subString method can be used to extract a parcial string 
from a string varriable. I also know that indexOf method can be used to find a 
character or group of characters within a string varriable. I am not sure how 
to insert, or even replace a character or group of characters within a string 
varriable. Can someone help me with this issue? Thanks.

  Gilbert Neiva

Other related posts: