Handling the TAB character in Java

I'm going through a configuration file with a RandomAccessFile reader. I have a configuration option which is one (1) tab away from the start of the line. When my reader gets this line, would I be able to just tell it to skip one character and then start reading, or does the tab character not work that way?

Example:

This is a line This line has a tab

Let's say I've loaded the second line into my reader. If I'm playing with that String and I do currentLine = currentLine.subString(1);

Would that give me:

currentLine = "This line has a tab";

Thanks for your help.

2

3 Answers

Yes the tab character is one character. You can match it in java with "\t".

0

You can also use the tab character '\t' to represent a tab, instead of "\t".

char c ='\t'; // tabulator
char c =(char)9; // tabulator

Or you could just perform a trim() on the string to handle the case when people use spaces instead of tabs (unless you are reading makefiles)

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like