Thursday, 26 May 2016

replaceall - Java Remove Dash In String Array





Currently I am trying to remove dash in my string array. The code that I tried below didn't work.



splitTimeStamp[0].replaceAll("[\\s\\-()]", "");
System.out.println(splitTimeStamp[0]);



Got the replaceAll code from another stackoverflow page.



Thanks in advance!


Answer



The method returns a new String. The original one isn't changed.
You need to save the result like this



splitTimeStamp[0] = splitTimeStamp[0].replaceAll("[\\s\\-()]", "");
System.out.println(splitTimeStamp[0]);


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...