P
P
parkito2016-03-02 20:38:05
Java
parkito, 2016-03-02 20:38:05

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);

However, I can not catch this very tabulation.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
parkito, 2016-03-02
@parkito

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);
            }

Doesn't catch end of line

X
xmoonlight, 2016-03-02
@xmoonlight

" " (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 question

Ask a Question

731 491 924 answers to any question