Search code examples
javaandroidstringreplacestrip

How do i remove/strip specific string in java


From AWS SNS I am reciving following response in my android app

{default={"messageType": "WRITE"}}

I need to achieve this and I can assign the above response only to either String or String datatype variable

{"messageType": "WRITE"}

So how do I achieve this?


Solution

  • You can use String.substring() to do it :

    String stringSource = "{default={\"messageType\": \"WRITE\"}}";
    String newString = stringSource.substring(9, stringSource.length() - 1);
    System.out.println(newString);