Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
    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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

String Replace

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi All,
How replace the string that contains "(abc)" to "xyz".
Example
String s = "This is the (abc)" to "This is a Test".
The String.replaceAll and replaceFirst are unable replace.
Thanks
With regards
Josi
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
A String Object in Java is immutable so you cannot possibly modify the contents of a exisisting String. You can copy the contents to a StringBuffer and then replace the old string with the new one and then point the newly modified string to the Original one.
Say for Example
Pseudo code will look like
String S = "Will Replace abc to xyz";
StringBuffer sb = new StringBuffer(s);
sb.replace()
and then assign the sb value to s again.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
"amit@apollo Dubey",
Please read the rules for display names here.
Your display name is not valid. We require your display name to be two words: your first name, a space, then your last name. Fictitious names are not allowed.
Please edit your profile so that your display name is valid. Accounts with invalid display names get deleted, often without warning.
thanks,
Dave.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Raj, please don't post the same question in multiple forums. It wastes the time of others if they don't realize a question was already answered in another forum. Followup here please. Thanks.
 
    Bookmark Topic Watch Topic
  • New Topic