Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #2107
| Path | csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.datemas.de!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Knute Johnson <nospam@knutejohnson.com> |
| Newsgroups | comp.lang.java.help |
| Subject | Re: problem delimiting a string |
| Date | Tue, 25 Sep 2012 21:24:00 -0700 |
| Organization | A noiseless patient Spider |
| Lines | 38 |
| Message-ID | <k3u010$d7r$1@dont-email.me> (permalink) |
| References | <k3tnen$75t$1@dont-email.me> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Wed, 26 Sep 2012 04:24:00 +0000 (UTC) |
| Injection-Info | mx04.eternal-september.org; posting-host="9b3fcb0d22708969e4dc99e7aa0ef1f9"; logging-data="13563"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+7kR72W6FJ5Z4YbMnFDSST" |
| User-Agent | Mozilla/5.0 (Windows NT 5.1; rv:15.0) Gecko/20120907 Thunderbird/15.0.1 |
| In-Reply-To | <k3tnen$75t$1@dont-email.me> |
| Cancel-Lock | sha1:+RjZi8NwTaFF8E9hWjfMst9hRU0= |
| Xref | csiph.com comp.lang.java.help:2107 |
Show key headers only | View raw
On 9/25/2012 6:57 PM, bilsch wrote:
> The fragment with the delimiting problem is listed below. The objective
> is to get Scanner to accept firstname midname and lastname as a single
> string using the ENTER key as the string delimiter rather than use the
> spaces between first, middle and last as delimiters. The two statements
> concerned with delimiting are straight out of a java text book so I
> assumed they would work (I don't actually know what they mean). The
> compiler complains about the line:
>
> Scanner.useDelimiter(lineSeparator);
>
> It says: cannot make static reference to the non-static method
> useDelimiter(String) from the type scanner. Your comments will be
> appreciated. TIA. The fragment is as follows:
>
> /* Extracts initials from whole name
> File Ch2Monogram.java
> */
> import java.util.*;
> class Ch2Monogram2a {
>
> public static void main(String[] args){
>
> String partName, firstName, midName, lastName;
> Scanner console = new Scanner(System.in);
> String lineSeparator = System.getProperty("line.separator");
> Scanner.useDelimiter(lineSeparator);
> System.out.println("Enter your whole name: first middle last");
> }
> }
console is an instance of a Scanner object. If useDelimeter() were a
static method of the class Scanner you could use that line but it is
not. Use console.useDelimeter(lineSeparator) instead.
--
Knute Johnson
Back to comp.lang.java.help | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
problem delimiting a string bilsch <bilsch01@gmail.com> - 2012-09-25 18:57 -0700 Re: problem delimiting a string Knute Johnson <nospam@knutejohnson.com> - 2012-09-25 21:24 -0700 Re: problem delimiting a string Roedy Green <see_website@mindprod.com.invalid> - 2012-09-26 09:45 -0700
csiph-web