How on the way (for example, d:\\WrkFld\\JJJ\\Адреса or d:\WrkFld\JJJ\Адреса ) to determine the number of back slashes ( \\ or \ )?

  • When publishing a question, there is a double slash "\\" in the first variant of the path replaced with a single "\" !!!! - Leonid05-05
  • Update your question according to the guidelines for keeping discussions on Stack Overflow , instead of posting comments. - Mikhail Vaysman

2 answers 2

The answer is taken here

 int count = line.length() - line.replace("\\", "").length(); 
  • Ahem, and what it can not be done do not create a new line? Same what expenses are not necessary - pavel
  • line.replace ("\\", "") can not be used - the first variable "\\" char, the second - String. replace (char, char). - Leonid05-05
  • @ Leonid05-05 there are both String parameters. - Mikhail Vaysman

It is possible so:

 int count = 0; for (int i = 0; i < str.length(); i++) if (str.charAt(i) == '\\') count++;