Stripping control characters from a string.

P

Paulers

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!
 
A

Arne Vajhøj

Paulers 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.

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
 
D

Daniel Pitts

Paulers said:
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.
 
P

Paulers

Paulers 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.
 [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!
 
A

Arne Vajhøj

Paulers said:
Paulers 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.
[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
 
E

Evans

Paulers 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.
 [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

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
 
P

Paulers

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! :)
 
R

Roedy Green

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top