Results 1 to 3 of 3
  1. #1
    Mayur is offline Member
    Join Date
    Jan 2009
    Posts
    24
    Rep Power
    0

    Default Replacing the chars within a string.

    Hello all. What I am trying to do is transpose each letter in a string and putting that string into a new string that will go into a new array.

    EDIT: Ok I got it to work but the output is weird now on some of them. I was hoping if someone can explain.

    EDIT: REMOVED CODE TO PROTECT MYSELF FROM PEOPLE IN MY CLASS FINDING IT AND COPYING IT. PROFESSOR USES A SCRIPT TO MATCH ANY SIMILARITIES IN CODE TO PREVENT CHEATING.

    As you can see the words in bold in the output, the first letter does not go in order.

    Any help would be greatly appreciated.
    Last edited by Mayur; 03-27-2009 at 04:01 AM.

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    Check the Method Detail for the replace method in the String api.
    Java Code:
    String replace(char oldChar, char newChar)
    It replaces all instances of oldChar with newChar.
    Java Code:
    //theTrWord = theTrWord.replace(theTrWord.charAt(c2),
    //                              transLetter);
    theTrWord = theTrWord.substring(0, c2) +
                String.valueOf(transLetter) +
                theTrWord.substring(c2+1);

  3. #3
    Mayur is offline Member
    Join Date
    Jan 2009
    Posts
    24
    Rep Power
    0

Similar Threads

  1. replacing backslashes in String Object
    By nishiz in forum Advanced Java
    Replies: 9
    Last Post: 12-02-2010, 12:31 AM
  2. Help Replacing String
    By 7oclock in forum New To Java
    Replies: 5
    Last Post: 02-14-2009, 07:31 AM
  3. How to print chars with symbols from a string
    By blacksky in forum New To Java
    Replies: 23
    Last Post: 01-06-2009, 01:14 PM
  4. Replies: 1
    Last Post: 05-07-2008, 01:19 AM
  5. splitting string and replacing
    By itsme in forum New To Java
    Replies: 1
    Last Post: 12-11-2007, 03:08 PM

Posting Permissions

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