• Post Reply Bookmark Topic Watch Topic
  • New Topic

String replace function??!?  RSS feed

 
R Harvey
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I'm looking for a simple replace function, to remove certain portions of a string, for example:
str1 = "hello my name is robin"
str2 = "robin"
str3 = replace(str1, str2)
str3 = "hello my name is "
I'm aware that i could use a regular expression (yes, i looked at the java api first!!!), but all i want is a simple replace function. That's not too much to ask, is it!!?! Regular expressions just seems like a sledgehammer to a wall nut...
Many thanks
Robin
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you just want to *remove* parts of a String, you could simply use the substring method. Use indexOf to find the part you want to remove.
A regular expression might still be simpler, though...
 
R Harvey
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ilja!
You're right, all i need to do is remove part of a string, so you've solved it!
Many thanks
Robin
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!