altering characters in a string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Katie87
    New Member
    • Oct 2007
    • 9

    #1

    altering characters in a string

    Hi, i need to do some character replacements in a string.
    heres what i have to do, lets say i have the string x= ABCD
    i would have to change the character at index 0 to 1, then at 2 to 4, and so on.
    i tried to do x.replace(x.cha rAt(0), x.charAt(1)), but then what happened was if the characters in the string were the same, it replaced all of them by the character at one.
    does anyone know how i could do this so this doesn 't happen.

    thanks
    kate
  • Katie87
    New Member
    • Oct 2007
    • 9

    #2
    Ok and there's a bit more, if anyone can give me any ideas for it would be great.

    ok so i have my string x= "ABCEFGH"
    i need to first check if the length is a multiple of 6.
    if it is not, i need to add the # character to the end to make it a multiple of 6.
    then i need to take the first six, and do the replacements i mentionned above, and then add the number 0 in front of it, since i didn't have to add any # signs to it. then i have to take the second chunk of six, and do the same thing, except i have to add the the number 5 in front, since i added 5#'s to it. any ideas??
    im really stuck...
    thanks

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by Katie87
      Ok and there's a bit more, if anyone can give me any ideas for it would be great.

      ok so i have my string x= "ABCEFGH"
      i need to first check if the length is a multiple of 6.
      if it is not, i need to add the # character to the end to make it a multiple of 6.
      then i need to take the first six, and do the replacements i mentionned above, and then add the number 0 in front of it, since i didn't have to add any # signs to it. then i have to take the second chunk of six, and do the same thing, except i have to add the the number 5 in front, since i added 5#'s to it. any ideas??
      im really stuck...
      thanks
      You should be able to find everything you need in the specs for the String class.

      Comment

      Working...