java - How to check weather string contains single backslash? -


i want check if string contains "\" or not. used string method contains(), not working

string path = "d:\steve\"; if(path.contains("\"){     path = path.replaceall("\\\\",""); } 

use escape character \

public class test{     public static void main(string[] args) {         string str = "a\\b";         system.out.println(str.contains("\\"));     } } 

a character preceded backslash (\) escape sequence , has special meaning compiler.

https://docs.oracle.com/javase/tutorial/java/data/characters.html


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -