-1

I am getting a string as "\123" from input and since \ with number is a valid syntax, java is converting it to ASCII. But I want to treat it as "\123". I was trying to search for raw strings as python but could not find anything. Also tried to check escape-utils but it is also not giving the expected output.

Any pointers to resolve the issue are appreciated.

Gaurav Jeswani
  • 4,410
  • 6
  • 26
  • 47
Aditya
  • 1
  • 1
  • 1
    Your question is unclear. Why would the escaping rules for *source code* matter when your string is coming from *user input*? – Jörg W Mittag Aug 27 '20 at 06:25
  • 1
    I cannot reproduce your problem. This works perfectly fine: `class Main { public static void main(String[] args) { var s = System.console().readLine(); System.out.println(s); }}`. – Jörg W Mittag Aug 27 '20 at 06:33
  • You would have to go through the string and check for escape characters and append \ or use escapeutils. https://stackoverflow.com/questions/7888004/how-do-i-print-escape-characters-in-java has an excellent example on how to do it. – Arundeep Chohan Aug 27 '20 at 06:39
  • Can you share your code and Input? – Gaurav Jeswani Aug 27 '20 at 07:03

1 Answers1

0

You have to escape it. Try printing "\\123"

Gaurav Jeswani
  • 4,410
  • 6
  • 26
  • 47