Search code examples
javastringdelimiterspace

ignoring the space delimiter in java


I am looking for a way to input a sentance as a single string, how would I do this? I could also just use a file as an input (.txt), but I don't know how to approach it.

I basically want to ignore the 'space' delimiter, and need help finding out how

what I have so far:

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);

Edit: added src I'm working on an encoder for me and some friends, and want to do sentances at a time instead of words at a time. Yes, they will end with a period.


Solution

  • Set the delimiter to ";", if you want to use ";" as delimiter:

    input.useDelimiter (";")