enaiman Posted November 20, 2007 Share Posted November 20, 2007 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 More sharing options...
Nahuel Posted November 20, 2007 Share Posted November 20, 2007 (edited) 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 November 20, 2007 by Nahuel Link to comment Share on other sites More sharing options...
enaiman Posted November 20, 2007 Author Share Posted November 20, 2007 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 :) Link to comment Share on other sites More sharing options...
Nahuel Posted November 20, 2007 Share Posted November 20, 2007 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 Link to comment Share on other sites More sharing options...
dani Posted November 20, 2007 Share Posted November 20, 2007 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? Link to comment Share on other sites More sharing options...
enaiman Posted November 20, 2007 Author Share Posted November 20, 2007 @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 ) ... 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 More sharing options...
enaiman Posted November 20, 2007 Author Share Posted November 20, 2007 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 More sharing options...
enaiman Posted November 23, 2007 Author Share Posted November 23, 2007 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 :) Link to comment Share on other sites More sharing options...
Nahuel Posted November 23, 2007 Share Posted November 23, 2007 I never saw your reply... I think @CR and @CRLF are the same character... ;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 More sharing options...
weaponx Posted November 23, 2007 Share Posted November 23, 2007 In your test string you have 2 instances of @CR, are you only wanting to strip the first or all isolated @CR? Link to comment Share on other sites More sharing options...
enaiman Posted November 23, 2007 Author Share Posted November 23, 2007 I never saw your reply... I think @CR and @CRLF are the same character... ;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: 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 More sharing options...
weaponx Posted November 23, 2007 Share Posted November 23, 2007 This method works for me. $test = "Line 1" $test &= @CR & "Line 2" & @CRLF & @CR & "Line 3" & @CRLF MsgBox(0,"Strip all @CR (Ignoring @CRLF)",StringReplace($test, @CR, "")) MsgBox(0,"Strip only first @CR",StringReplace($test, @CR, "", 1)) Link to comment Share on other sites More sharing options...
Nahuel Posted November 23, 2007 Share Posted November 23, 2007 Ohh, that's true, sorry... weaponx's method seems to work great Link to comment Share on other sites More sharing options...
enaiman Posted November 23, 2007 Author Share Posted November 23, 2007 (edited) thanks, I'll try it right away ... nope 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 November 23, 2007 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now