0

I have a string Hi , Thank you for opening an account with XYZ. We're excited to have you on board.

I need to get rid of ' from the string and get equivalent character in place of it which is apostrophe (').

I need general code to replace the ascii characters.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197

2 Answers2

1

Use String.replace():

String str = "Hi , Thank you for opening an account with XYZ. We're excited to have you on board.";
str.replace("'","\'");
0

Here is example

public class Guru99Ex1 {
public static void main(String args[]) {
    String S1 = new String("the quick fox jumped");
    System.out.println("Original String is ': " + S1);
    System.out.println("String after replacing 'fox' with 'dog': " + S1.replace("fox", "dog"));
    System.out.println("String after replacing all 't' with 'a': " + S1.replace('t', 'a'));

}

}

ATIQ UR REHMAN
  • 431
  • 3
  • 12