• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

String replace function??!?

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic