我如何使用System.getProperty(" line.separator")。toString()? [英] How do I use System.getProperty("line.separator").toString()?

查看:149
本文介绍了我如何使用System.getProperty(" line.separator")。toString()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Tab-delimited String(表示一个表),它传递给我的方法。当我将它打印到命令行时,它看起来像一个包含行的表:

I have a Tab-delimited String (representing a table) that is passed to my method. When I print it to the command line, it appears like a table with rows:

http://i.stack.imgur.com/2fAyq.gif

命令窗口已正确缓冲。我的想法是每行之前或之后肯定有一个新的行字符。

The command window is correctly buffered. My thinking is that there is definitely a new line character before or after each row.

我的问题是我想将传入的字符串拆分成代表行的单个字符串的表。到目前为止,我有:

My problem is that I want to split up the incoming string into individual strings representing the rows of the table. So far I have:

private static final String newLine = System.getProperty("line.separator").toString();
private static final String tab = "\t";
private static String[] rows;
...

rows = tabDelimitedTable.split(newLine);    //problem is here

System.out.println();
System.out.println("################### start debug ####################");

System.out.println((tabDelimitedTable.contains(newLine)) ? "True" : "False");

System.out.println("#################### end debug###################");
System.out.println();

输出:

################### start debug ####################
False
#################### end debug###################

显然,字符串中有一些东西告诉操作系统开始换行。但它显然不包含换行符。

Obviously there is something in the string telling the OS to start a new line. Yet it apparently contains no newline characters.

在Windows XP SP3上运行最新的JDK。

Running the latest JDK on Windows XP SP3.

任何想法?

推荐答案

尝试

rows = tabDelimitedTable.split("[" + newLine + "]");

这应解决正则表达式问题。

也不是那么重要但返回类型

Also not that important but return type of

System.getProperty("line.separator")

字符串所以不需要调用toString()。

is String so no need to call toString().

这篇关于我如何使用System.getProperty(" line.separator")。toString()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆