Jump to content
Sign in to follow this  
enaiman

StringRegExp need help

Recommended Posts

enaiman

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

Share this post


Link to post
Share on other sites
Nahuel

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

Share this post


Link to post
Share on other sites
enaiman

Thanks Nahuel but that doesn't work as I need because there is another @CR at the end of the line - I want to keep the end of the line unchanged and only to replace the begining.


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

Share this post


Link to post
Share on other sites
Nahuel

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

Share this post


Link to post
Share on other sites
dani

Can't you use StringReplace, search for @CRLF or @LF and replace it by "", and set count to 1 to only replace the 1st occurrence?

Share this post


Link to post
Share on other sites
enaiman

@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 :)

Share this post


Link to post
Share on other sites
enaiman

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

Share this post


Link to post
Share on other sites
enaiman

Sorry for "bumping" my thread but I really need some help.

Thanks,


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

Share this post


Link to post
Share on other sites
Nahuel

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

Share this post


Link to post
Share on other sites
weaponx

In your test string you have 2 instances of @CR, are you only wanting to strip the first or all isolated @CR?

Share this post


Link to post
Share on other sites
enaiman

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

Share this post


Link to post
Share on other sites
Nahuel

Ohh, that's true, sorry... weaponx's method seems to work great :P

Share this post


Link to post
Share on other sites
enaiman

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

Share this post


Link to post
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
Sign in to follow this  

×