开发者

Handling the TAB character in Java

开发者 https://www.devze.com 2023-03-07 21:51 出处:网络
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 ab

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.


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


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消