Stripping control characters from a string.

Discussion in 'Java' started by Paulers, Jun 28, 2008.

  1. Paulers

    Paulers Guest

    Hello all,

    I am telnetting to a server and attempting to parse the output. I am
    having difficulty stripping our the terminal control characters. Could
    someone point me in the right direction? he output.

    12900 5319

    Thanks!
     
    Paulers, Jun 28, 2008
    #1
    1. Advertising

  2. Paulers

    Arne Vajhøj Guest

    Paulers wrote:
    > I am telnetting to a server and attempting to parse the output. I am
    > having difficulty stripping our the terminal control characters. Could
    > someone point me in the right direction? he output.
    >
    > 12900 5319


    String s2 = s.replaceAll("\\p{Cntrl}", "");

    will remove all control characters, but maybe you would want
    to remove the entire escape sequences.

    Arne
     
    Arne Vajhøj, Jun 28, 2008
    #2
    1. Advertising

  3. Paulers

    Daniel Pitts Guest

    Paulers wrote:
    > Hello all,
    >
    > I am telnetting to a server and attempting to parse the output. I am
    > having difficulty stripping our the terminal control characters. Could
    > someone point me in the right direction? he output.
    >
    > 12900 5319
    >
    > Thanks!

    Don't enable virtual terminal emulation on the server side.

    --
    Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
     
    Daniel Pitts, Jun 28, 2008
    #3
  4. Paulers

    Paulers Guest

    On Jun 27, 5:46 pm, Arne Vajhøj <> wrote:
    > Paulers wrote:
    > > I am telnetting to a server and attempting to parse the output. I am
    > > having difficulty stripping our the terminal control characters. Could
    > > someone point me in the right direction? he output.

    >
    > >  [11;1H12 [11;5H900  [11;11H5319

    >
    > String s2 = s.replaceAll("\\p{Cntrl}", "");
    >
    > will remove all control characters, but maybe you would want
    > to remove the entire escape sequences.
    >
    > Arne


    Yes you are correct, I'm looking to remove it all, for example [11;1H

    thanks for the reply!
     
    Paulers, Jun 28, 2008
    #4
  5. Paulers

    Arne Vajhøj Guest

    Paulers wrote:
    > On Jun 27, 5:46 pm, Arne Vajhøj <> wrote:
    >> Paulers wrote:
    >>> I am telnetting to a server and attempting to parse the output. I am
    >>> having difficulty stripping our the terminal control characters. Could
    >>> someone point me in the right direction? he output.
    >>> [11;1H12 [11;5H900 [11;11H5319

    >> String s2 = s.replaceAll("\\p{Cntrl}", "");
    >>
    >> will remove all control characters, but maybe you would want
    >> to remove the entire escape sequences.

    >
    > Yes you are correct, I'm looking to remove it all, for example [11;1H


    String s3 = s.replaceAll("\u001B\\[\\d+;\\d+H", "");

    replaces all the cursor positioning escape sequences.

    If you need to remove other escape sequences, then you will
    need to replace other patterns - I am not aware of a single
    regex that matches all valid VT escape sequences.

    Arne
     
    Arne Vajhøj, Jun 28, 2008
    #5
  6. Paulers

    Evans Guest

    On Jun 28, 2:25 am, Paulers <> wrote:
    > On Jun 27, 5:46 pm, Arne Vajhøj <> wrote:
    >
    > > Paulers wrote:
    > > > I am telnetting to a server and attempting to parse the output. I am
    > > > having difficulty stripping our the terminal control characters. Could
    > > > someone point me in the right direction? he output.

    >
    > > >  [11;1H12 [11;5H900  [11;11H5319

    >
    > > String s2 = s.replaceAll("\\p{Cntrl}", "");

    >
    > > will remove all control characters, but maybe you would want
    > > to remove the entire escape sequences.

    >
    > > Arne

    >
    > Yes you are correct, I'm looking to remove it all, for example [11;1H
    >
    > thanks for the reply!


    I think I wrote something a while ago to do something close to what
    you're after.
    Unfortunately, am at friend's and this computer doesn't have Java
    installed so can't really have a go at it from here.

    Will post if later when I get home if you're still in need of it then.

    Evans
    http://www.jroller.com/evans/entry/jquantlib_released
     
    Evans, Jun 28, 2008
    #6
  7. Paulers

    Paulers Guest

    On Jun 28, 5:10 am, Evans <> wrote:
    > On Jun 28, 2:25 am, Paulers <> wrote:
    >
    >
    >
    > > On Jun 27, 5:46 pm, Arne Vajhøj <> wrote:

    >
    > > > Paulers wrote:
    > > > > I am telnetting to a server and attempting to parse the output. I am
    > > > > having difficulty stripping our the terminal control characters. Could
    > > > > someone point me in the right direction? he output.

    >
    > > > > [11;1H12 [11;5H900 [11;11H5319

    >
    > > > String s2 = s.replaceAll("\\p{Cntrl}", "");

    >
    > > > will remove all control characters, but maybe you would want
    > > > to remove the entire escape sequences.

    >
    > > > Arne

    >
    > > Yes you are correct, I'm looking to remove it all, for example [11;1H

    >
    > > thanks for the reply!

    >
    > I think I wrote something a while ago to do something close to what
    > you're after.
    > Unfortunately, am at friend's and this computer doesn't have Java
    > installed so can't really have a go at it from here.
    >
    > Will post if later when I get home if you're still in need of it then.
    >
    > Evanshttp://www.jroller.com/evans/entry/jquantlib_released


    Thanks! :)
     
    Paulers, Jun 28, 2008
    #7
  8. Paulers

    Roedy Green Guest

    On Fri, 27 Jun 2008 17:37:27 -0700 (PDT), Paulers
    <> wrote, quoted or indirectly quoted someone
    who said :

    >I am telnetting to a server and attempting to parse the output. I am
    >having difficulty stripping our the terminal control characters. Could
    >someone point me in the right direction? he output.


    Simple way would be something like this:

    static String strip( String s )
    {
    final StringBuilder sb = new StringBuilder( s.length() )
    for ( int i=0; i<s.length(); i++ )
    {
    final char c = s.charAt( i );
    if ( c >= 0x20 )
    {
    sb.append( c );
    }
    }
    return sb.toString();

    --

    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
     
    Roedy Green, Jun 29, 2008
    #8
    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. =?Utf-8?B?THU=?=
    Replies:
    4
    Views:
    1,491
    Joerg Jooss
    Sep 2, 2005
  2. VJ

    Stripping characters...

    VJ, Jan 17, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    462
    John Timney \( MVP \)
    Jan 17, 2006
  3. et
    Replies:
    3
    Views:
    746
  4. Replies:
    1
    Views:
    458
    Hans Kesting
    Jun 1, 2006
  5. Chris Causer

    Stripping characters off a string

    Chris Causer, Oct 21, 2008, in forum: Ruby
    Replies:
    7
    Views:
    151
    Chris Causer
    Oct 21, 2008
Loading...

Share This Page