Jump to content

StringRegExp need help


enaiman
 Share

Recommended Posts

I'm using a multiline editbox in a terminal-like application. When the line received starts with a @CR that character is displayed (or ... it may be @LF , not 100% sure which) and it looks ugly is like a vertical bar at the begining of line.

How can I get rid of that?

the bad line format is: @CR "text here"

the desired format is: "text here"

what would be the synthax?

Thank you,

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

I don't think you need StringRegExp. How about StringStripCR?

$text = @CR & "Hello" 
MsgBox(0, "",$text)
$textnew = StringStripCR($text)
MsgBox(0, "", $textnew)

edit:typo.

Edited by Nahuel
Link to comment
Share on other sites

Oh, I see.. then StringStripWS() should do it better:

$text = @CR & "Hello" &@CR
MsgBox(0, "",StringReplace($text,@CR,"*"))
$textnew = StringStripWS($text,1)
MsgBox(0, "",StringReplace($textnew,@CR,"*"))

Or, my StringRegExp() method:

$text = @CR & "Hello" &@CR
MsgBox(0, "",StringReplace($text,@CR,"*"))
$textnew = StringRegExp($text,"(\r)(.*?\r)",1)
MsgBox(0, "",StringReplace($textnew[1],@CR,"*"))

I replaced the @CR's for stars in the messageboxes so you can tell the difference :P

Link to comment
Share on other sites

@Nahuel - thanks, been looking for something like this: (\r)(.*?)

About StringStripWS using flag 1 - it might work as well (haven't noticed that CE nad LF are regarded as WS :P ) ... well everyday we learn something new ...

@D4ni - thanks, it might work as well - I've used StringReplace before but didn't think about replacing only 1st occurence ;) ... another thing to remember :)

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

hmmm ... I guess I need more help here ...

the string might look like:

@CR&"test string"&@CRLF&@CR&"another line here"&@CRLF

and what I want to do is strip only those "isolated" @CR leaving the @CRLF alone. Any idea?

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

I never saw your reply...

I think @CR and @CRLF are the same character... :P

;Same
MsgBox(0,"",Asc(@CR))
MsgBox(0,"",Asc(@CRLF))
;different
MsgBox(0,"",Asc(@LF))

So I don't think it's possible unless the order of the @CR's and @CRLF are always the same..?

Link to comment
Share on other sites

I never saw your reply...

I think @CR and @CRLF are the same character... :P

;Same
MsgBox(0,"",Asc(@CR))
MsgBox(0,"",Asc(@CRLF))
;different
MsgBox(0,"",Asc(@LF))

So I don't think it's possible unless the order of the @CR's and @CRLF are always the same..?

@Nahuel - guess you're making a mistake here - @CRLF is a group of chars equal to @CR&@LF

see next example:

;Same
MsgBox(0,"",Asc("a"))
MsgBox(0,"",Asc("abcd"))

@weaponx

The lines should be always separated by @CRLF - all extra @CR mess the editbox - see the image:

post-18882-1195788521_thumb.jpg

I would like these @CR stripped - it is difficult because they appear sometimes (not always) and I don't know when and where.

Thanks for help,

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

thanks, I'll try it right away

... nope :P

It works with the test example but not in my case.

I've made a function to show CR and LF

Func show_crlf($ssstttrrr)
    If StringInStr($ssstttrrr, @CRLF) Then $ssstttrrr = StringReplace($ssstttrrr, @CRLF, "@CRLF")
    If StringInStr($ssstttrrr, @CR) Then $ssstttrrr = StringReplace($ssstttrrr, @CR, "@CR")
    If StringInStr($ssstttrrr, @LF) Then $ssstttrrr = StringReplace($ssstttrrr, @LF, "@LF")
    Return $ssstttrrr
EndFunc

Ran the string and here is what I got:

@CRLF
telnet session telnet0 on /dev/ptyb0 @CRLF
@CRLF
login: admin @CRLF

@CR password: @CRLF
@CR@CRLF
@CR ExtremeXOS @CRLF


Copyright (C) 2000-2007 Extreme Networks. All rights reserved.@CRLF
Protected by US Patent Nos: 6,678,248; 6,104,700; 6,766,482; 6,618,388; 6,034,957; 6,859,438; 6,912,592; 6,954,436; 6,977,891; 6,980,550; 6,981,174; 7,003,705; 7,012,082; 7,046,665; 7,126,923; 7,142,509; 7,149,217; 7,152,124; 7,154,861.@CRLF
==============================================================================@CRLF

I separated them to improve visibility.

You can notice those @CR at the begining - they're responsible for these "artifacts" on my editbox.

EDIT: found something finally, after trying alot of things:

$recvd = StringReplace($recvd, @CRLF, "%")
    $recvd = StringStripCR($recvd)
    $recvd = StringReplace($recvd, "%",@CRLF)

where $recvd is my string.

It works but it looks ... inefficient, that's why I preferred something like StringRegExp ...

Edited by enaiman

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...