stringtokenizer that traps ASCII linebreaks

Discussion in 'Java' started by wnstnsmith@yahoo.com, Feb 11, 2004.

  1. Guest

    Dear all,

    How do i define a stringtokenizer that traps chr13, chr10 combinations?

    tia
    WS
     
    , Feb 11, 2004
    #1
    1. Advertising

  2. Adam Jenkins Guest

    wrote:
    > Dear all,
    >
    > How do i define a stringtokenizer that traps chr13, chr10 combinations?
    >
    > tia
    > WS


    You can't exactly do this with StringTokenizer, since it doesn't support
    splitting on specific multi-char patterns. You could say

    StringTokenizer stok = new StringTokenizer(string, "\r\n");

    which would split "string" at each \013\010, but it would also split on
    just a \013 or \010 or \013\013, etc. If you really need to split at
    each \r\n, then you can use String.split, as in

    String[] tokens = string.split("\r\n");

    Adam
     
    Adam Jenkins, Feb 11, 2004
    #2
    1. Advertising

  3. Guest

    Thanks very much indeed, that does it. Guess my mistake was to have the
    tokenizer look for '\r' + '\n' + "blablabla", instead of "\r\n". You can
    imagine that had me wondering...

    WS
     
    , Feb 11, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Panchi51

    LP64 FAQ tricks/tips/traps.

    Panchi51, Jul 13, 2003, in forum: C Programming
    Replies:
    2
    Views:
    535
  2. abbu
    Replies:
    3
    Views:
    396
    viggy
    Nov 30, 2006
  3. Replies:
    2
    Views:
    1,011
  4. Dirk Van de moortel

    Receiving snmp traps in perl on Win platform?

    Dirk Van de moortel, Jun 2, 2008, in forum: Perl
    Replies:
    1
    Views:
    2,943
    Dirk Van de moortel
    Jun 4, 2008
  5. Joe Hughes

    Python 3 and SNMP Traps

    Joe Hughes, Dec 29, 2010, in forum: Python
    Replies:
    0
    Views:
    882
    Joe Hughes
    Dec 29, 2010
Loading...

Share This Page