Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Stripping control characters from a string. (http://www.velocityreviews.com/forums/t622670-stripping-control-characters-from-a-string.html)

Paulers 06-28-2008 12:37 AM

Stripping control characters from a string.
 
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!

Arne Vajhøj 06-28-2008 12:46 AM

Re: Stripping control characters from a string.
 
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

Daniel Pitts 06-28-2008 12:54 AM

Re: Stripping control characters from a string.
 
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/>

Paulers 06-28-2008 01:25 AM

Re: Stripping control characters from a string.
 
On Jun 27, 5:46*pm, Arne Vajhøj <a...@vajhoej.dk> 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!

Arne Vajhøj 06-28-2008 01:43 AM

Re: Stripping control characters from a string.
 
Paulers wrote:
> On Jun 27, 5:46 pm, Arne Vajhøj <a...@vajhoej.dk> 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


Evans 06-28-2008 12:10 PM

Re: Stripping control characters from a string.
 
On Jun 28, 2:25*am, Paulers <paulers85...@gmail.com> wrote:
> On Jun 27, 5:46*pm, Arne Vajhøj <a...@vajhoej.dk> 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

Paulers 06-28-2008 09:36 PM

Re: Stripping control characters from a string.
 
On Jun 28, 5:10 am, Evans <onyx...@gmail.com> wrote:
> On Jun 28, 2:25 am, Paulers <paulers85...@gmail.com> wrote:
>
>
>
> > On Jun 27, 5:46 pm, Arne Vajhøj <a...@vajhoej.dk> 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! :)

Roedy Green 06-29-2008 01:28 AM

Re: Stripping control characters from a string.
 
On Fri, 27 Jun 2008 17:37:27 -0700 (PDT), Paulers
<paulers85213@gmail.com> 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


All times are GMT. The time now is 02:48 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57