![]() |
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. [11;1H12[11;5H900 [11;11H5319 Thanks! |
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. > > [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 |
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. > > [11;1H12[11;5H900 [11;11H5319 > > Thanks! Don't enable virtual terminal emulation on the server side. -- Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/> |
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! |
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 |
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 |
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! :) |
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.