誰能告訴我這是爲什麼正常工作:如何從用戶輸入中分割「 n」?
String wanttosplit = "asdf...23\n..asd12";
String[] i = wanttosplit.split("\n");
output are:
i[0] = asdf...23
i[1] = ..asd12
當我想從用戶一樣獲得數據:
import java.util.Scanner;
Scanner scan = new Scanner(System.in);
String wanttosplit = scan.next(); //user enter asdf...23\n..asd12 on the keyboard
String[] i = wanttosplit.split("\n");
output are:
i[0] = asdf...23\n..asd12
爲什麼它沒有在第一個例子中分裂樣的呢?
你試過拆分(「\ n \ r」)嗎? – sai
您是否嘗試過拆分(「\\ n」)? – GregaMohorko