Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Messy Problem - String.replaceAll()

 
Stephen Foy
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20880
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Henry Wong
author
Marshal
Pie
Posts: 20880
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic