Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get index of Escape Character in a String?

Tags:

java

How to get index of Escape Character in a String?

String test="1234\567890";
System.out.println("Result : "+test.lastIndexOf("\\"));

Result i get: -1

Result i need: 4

like image 263
Devendra Singh Avatar asked Nov 25 '25 22:11

Devendra Singh


1 Answers

Your original String doesn't contain \. Which means you are searching something which does not exist. Inorder to add \ to your string. You have to escape while adding

String test="1234\\567890";
System.out.println("Result : "+test.lastIndexOf("\\"));

Should work.

enter image description here

In your case look at the last line in the table.

like image 186
Suresh Atta Avatar answered Nov 27 '25 12:11

Suresh Atta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!