Java中TAB字符的处理
我正在使用 RandomAccessFile 阅读器浏览配置文件。我有一个配置选项,距离行开头一 (1) 个选项卡。当我的读者收到这一行时,我是否可以告诉它跳过一个字符然后开始阅读,或者制表符不能那样工作?
示例:
This is a line
This line has a tab
假设我已将第二行加载到阅读器中。如果我正在玩那个字符串并且我这样做 currentLine = currentLine.subString(1);
这会给我带来:
currentLine = "This line has a tab";
感谢您的帮助。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,制表符是一个字符。在java中可以用“\t”来匹配。
Yes the tab character is one character. You can match it in java with "\t".
您还可以使用制表符
'\t'
来表示制表符,而不是"\t"
。You can also use the tab character
'\t'
to represent a tab, instead of"\t"
.或者,您可以对字符串执行
trim()
来处理人们使用空格而不是制表符时的情况(除非您正在阅读 makefile)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)