[英]How to convert multi-line String to array of line keeping indentation
字符串变量中的 C 或 C++ 代码。 我想将该多行字符串变量转换为字符串列表,但我想保留缩进以在我的 angular 应用程序中显示代码。 这就是我正在做的
String diffContent = "multi line Java c or c++ code";
List<String> lines = IOUtils.readLines(new StringReader(diffContent));
但是我因此而失去了缩进。 有没有可能的方法来实现这一点。
尝试根据 "\n" 分割行:
String splitLines[] = diffContent.split("\n");
然后在新行中显示每个字符串。
尝试这个
String diffContent = "multi line Java c or c++ code";
String str[] = diffContent.split(" ");
List<String> al = new ArrayList<String>();
al = Arrays.asList(str);
for(String s: al){
System.out.println(s);
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.