小编Dyl*_*lan的帖子

使用myString.split("\n")时遇到问题;

我需要将输入字符串拆分成许多部分.拆分应该出现在"\n"(字面意思是反斜杠-n,而不是换行符).我想转此:

x = [2,0,5,5]\ny = [0,2,4,4]\ndraw y #0000ff\ny = y & x\ndraw y #ff0000
Run Code Online (Sandbox Code Playgroud)

进入这个:

x = [2,0,5,5]
y = [0,2,4,4]
draw y #0000ff
y = y & x
draw y #ff0000
Run Code Online (Sandbox Code Playgroud)

我原本以为stringArray = string.split("\n");这就足够了.

但它在以下代码中给出了与输入相同的输出:

public static void main(String[] args) throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    System.out.print("Enter Input\n");
    String s = br.readLine();
    NewInterpreter interpreter = new NewInterpreter(s);
    interpreter.run();
}

public NewInterpreter(String input) {
    this.input = input;
    this.index = 0;
    this.inputComponents = input.split("\n");
    System.out.println("Output: ");
    for(String …
Run Code Online (Sandbox Code Playgroud)

java string io split newline

13
推荐指数
1
解决办法
1250
查看次数

标签 统计

io ×1

java ×1

newline ×1

split ×1

string ×1