I am trying to edit a matlabfile and replace some of the coding parts init in some specific lines. However, using the format below to make the changes it wont change the line co
The replaceAll
method on String
takes a regular expression as an argument, and in regular expressions some characters have special meanings, such as the parentheses in your expression.
Simply use the replace
method instead, which takes literal strings:
String newline = line.replace("stream.Values(strmatch('Test',stream.Components,'exact'))", "New Data");
Don't be confused by the name of the method - the difference between replace
and replaceAll
is not in how many times they replace, but the difference is in that the first one takes literal strings and the second one takes a regular expression. It's in the Javadoc:
Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence.
public String replace(CharSequence target, CharSequence replacement) {