user3611574
user3611574

Reputation: 13

Creating Java String with Escape Sequence

I am trying to create a String which has the below value, but I am getting a syntax error. can anyone please help on this.

tr -d '\15\32' < shell.sh > com.sh

I need the final output in a String something like the above. This is what I've tried:

String s = "tr -d '\15\32' < shell.sh > com.sh";

But I am getting an error for the above code.

Upvotes: 0

Views: 49

Answers (1)

Denys S&#233;guret
Denys S&#233;guret

Reputation: 382454

A \ in a string literal starts an escape sequence.

Double the \ in a string literal :

String s = "tr -d '\\15\\32' < shell.sh > com.sh";

Upvotes: 2

Related Questions