aspose file tools*
The moose likes Beginning Java and the fly likes Messy Problem - String.replaceAll() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Messy Problem - String.replaceAll()" Watch "Messy Problem - String.replaceAll()" New topic
Author

Messy Problem - String.replaceAll()

Stephen Foy
Ranch Hand

Joined: Oct 17, 2005
Posts: 143
Basically im doing:

1. Search array for cells with a length of 1
2. If length is 1, research array.
3. In each cell, search through the string for the value of the cell in step 1
4. Remove this value from that String << this is where the problem is



Any ideas?


Stephen Foy - Microsoft Application Development Consultant
Stephen Foy
Ranch Hand

Joined: Oct 17, 2005
Posts: 143
I see, is there a way to achieve this, i tried using charAt to remove the specific character from the string. But to no avail.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18848
    
  40

Strings are immutable. The replaceAll() method doesn't change the string -- it just returns a new string with the values changed.

BTW, all you do with it is send it to the equals methods, which in turns, doesn't nothing with the result from that.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18848
    
  40

Originally posted by Stephen Foy:
I see, is there a way to achieve this, i tried using charAt to remove the specific character from the string. But to no avail.


Strings are immutable... *none* of the methods of the string class will change the string. You have to reassign the variable to the new string that is return.

For example... this won't work.



You need to do this instead...



Henry
 
 
subject: Messy Problem - String.replaceAll()