×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Regular Contributor
    Join Date
    Aug 2010
    Location
    Chennai, India.
    Posts
    176

    how to replace a string?

    Experts, I came to know that JavaMe doesn't hava replace method. How can i replace all the string to another string? Method like

    replace(String a, String b). ?

    Anyone did this before? please share your code?

  2. #2
    Registered User
    Join Date
    Jun 2010
    Location
    India
    Posts
    200

    Re: how to replace a string?

    use temp string & swap both string....
    thanks & Regards.
    Nilesh

  3. #3
    Registered User
    Join Date
    Apr 2011
    Posts
    15

    Re: how to replace a string?

    Hi Kumar

    Use to trneary operator ,it use easy swap string


    By
    chandru

  4. #4
    Regular Contributor
    Join Date
    Aug 2010
    Location
    Chennai, India.
    Posts
    176

    Re: how to replace a string?

    Thanks for your reply,

    Like this example...
    String str = "Her name is Tamana and Tamana is a good girl.";
    String strreplace = "Sonia";
    String result = str.replaceAll("Tamana", strreplace);
    System.out.println(result);
    Output: Her name is Sonia and Sonia is a good girl.
    I'm searching for replaceAll() method. I have one string, i want to replace all the string to another string from the original string?

    how can i implement replaceAll() method?

  5. #5
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,684

    Re: how to replace a string?

    That is called programming. Combine indexOf and substring methods in a loop.
    A step could be something like
    Code:
    int pos=str.indexOf("Tamana");
    if(pos>-1)
        str=str.substring(0,pos)+"Sonia"+str.substring(pos+"Tamana".length());
    and repeat if necessary.
    The advanced variant would use StringBuffer for storing the output, and toString it in a single step at the end.

Similar Threads

  1. Replies: 5
    Last Post: 2011-06-06, 06:37
  2. Replies: 6
    Last Post: 2011-03-24, 18:04
  3. find and replace string
    By kuddy_abc in forum Symbian
    Replies: 1
    Last Post: 2010-05-30, 08:42
  4. String search and replace
    By Zilppuri in forum Symbian
    Replies: 4
    Last Post: 2009-05-08, 19:41
  5. Replace a placeholder in _LIT with a string?
    By kaiten-sushi in forum Symbian
    Replies: 7
    Last Post: 2007-01-29, 15:23

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×