2012-05-20 87 views
-2

我正在寻找一种方法将单词串输入为单个字符串,我该怎么做? 我也可以使用一个文件作为输入(.txt),但我不知道如何处理它。忽略java中的空格分隔符

我基本上要忽略“空间”分隔符,以及需要帮助找出如何

是我到目前为止有:

Scanner input = new Scanner(System.in); 
    Random randomGenerator = new Random(); 
    int rand = randomGenerator.nextInt(10)+1; 
    System.out.print("Enter code to be encoded. End the text with a semicolon(;): "); 
    String in = input.next(); 
    System.out.println(); 
    System.out.println("Confirmation: Encode the following text? y to accept, n to decline"); 
    System.out.println(in); 

编辑: 加入SRC 我工作的编码器给我和一些朋友,并且一次只想做一次而不是一次一次的文字。是的,他们会以一段时间结束。

+0

到目前为止你有什么?也许nextline是你的解决方案,但我宁愿看到一些开始。 – porfiriopartida

+0

[Scanner ... nextLine](http://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html#nextLine()) –

+0

您对输入有什么限制?句子只在句子结尾?每行输入只有一句话吗? – apnorton

回答

2

如果您想使用“;”,请将分隔符设置为“;”作为分隔符:

input.useDelimiter (";") 
+0

谢谢。我认为它应该在行尾有分号? – Azulflame