Answer the question
In order to leave comments, you need to log in
How to recognize tabs when reading a file?
Hello. Please help me solve the problem.
I am reading a file line by line. I want that when in a file there comes the end of the line, the gap was deduced.
while (scanner.hasNext()) {
string=scanner.next();
if(string=="\t")
string1=string1+" ";
else
string1=string1+string;
}
System.out.println(string);
Answer the question
In order to leave comments, you need to log in
Sergei , for example
boolean a = false;
for (int i = 0; i < string.length(); i++) {
if (string.charAt(i) == '\r') {
a = true;
break;
}
}
if (a==true)
{string1 = string1 + string+" ";a=false;}
else
string1 = string1 + string;
// System.out.println(string);
}
" " (ASCII 32 (0x20)), a regular space.
"\t" (ASCII 9 (0x09)), tab character.
"\n" (ASCII 10 (0x0A)), line feed character.
"\r" (ASCII 13 (0x0D)), carriage return character.
"\0" (ASCII 0 (0x00)), NUL byte.
"\x0B" (ASCII 11 (0x0B)), vertical tab.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question