Zachlr Posted November 12, 2009 Share Posted November 12, 2009 As you may know, many telnet servers only work if you do not press the backspace key throughout the entire sequence. This is because the backspace key is sent as a character, rather than actually backspacing the input. It gets frustrating when you have to type a command all over again because you pressed "S" instead of "D". Well, I'm trying to develop a function that will convert the backspace character (ascii 8) into a proper string. Here is what I have so far. $text = "hi my name is zach" & Chr(8)& Chr(8)& Chr(8)& Chr(8) ;we'll say someone meant to delete the last four characters. MsgBox(0, "", $text) ;show the original text. MsgBox(0, "", BS($text)) ;show the fixed text Func BS($String) If StringLen($String) < 2 Then Return 0 $String = StringSplit($String, "") For $i = 1 To $String[0] If $String[$i] = Chr(8) Then ;check each character for the backspace character $String[$i-1] = "" ; if it is the BS char, then erase the previous character. For $n = $i To $String[0] -1 ;- $i ; shift all of the contents left to eliminate the space $String[$n] = $String[$n+1] Next EndIf Next Return $String ;return the fixed string. EndFunc Somehow this code seems to turn $string into "" by the end of the function. If you can help me fix it, or you know of another way to accomplish this, please post a reply. Thanks, Zach Link to comment Share on other sites More sharing options...
jvanegmond Posted November 12, 2009 Share Posted November 12, 2009 I was working on something like that before, but I solved it a bit different. Have a look: http://www.autoitscript.com/forum/index.php?showtopic=54147 github.com/jvanegmond Link to comment Share on other sites More sharing options...
Zachlr Posted November 13, 2009 Author Share Posted November 13, 2009 (edited) I was working on something like that before, but I solved it a bit different. Have a look: http://www.autoitscript.com/forum/index.php?showtopic=54147Thanks for the link. I think I'll be able to implement that into my script one way or another. EDIT: I'm going to look into the thread mentioned above, but I'm still opened to solutions. So, if you have anything, please tell me about it.EDIT: I'm under the impression that the method mentioned above will only work in a "per character" telnet session, not "per line". I'm not sure if it will work for my particular script.Thanks again, Zach Edited November 13, 2009 by Zachlr Link to comment Share on other sites More sharing options...
Malkey Posted November 13, 2009 Share Posted November 13, 2009 These two examples may help. $text = "hi my name" & Chr(8) & " is zach" & Chr(8) & Chr(8) & Chr(8) ;we'll say someone meant to delete the last three characters. MsgBox(0, "Original text", $text) ;show the original text. MsgBox(0, "BS(text)", BS($text)) ;show the fixed text Func BS($String) Local $sRet = "" If StringLen($String) < 2 Then Return 0 $String = StringSplit($String, "") For $i = 1 To $String[0] If $String[$i] <> Chr(8) Then $sRet &= $String[$i];check each character for the backspace character Else $sRet = StringTrimRight($sRet, 1) EndIf Next Return $sRet ;return the fixed string. EndFunc ;==>BS ;or ;======================================================================= $TextModified = StringRegExpReplace($text, "([^\x08]\x08)", "") ; Will not replace two BS next to each other. While StringInStr($TextModified, Chr(0x08)) $TextModified = StringRegExpReplace($TextModified, "([^\x08]\x08)", "") ; Replace anything and BS with nothing. Sleep(10) WEnd MsgBox(0, "RegExp", $TextModified) ;======================================================================== MsgBox(0, "Original text", $text) Link to comment Share on other sites More sharing options...
Zachlr Posted November 13, 2009 Author Share Posted November 13, 2009 These two examples may help. $text = "hi my name" & Chr(8) & " is zach" & Chr(8) & Chr(8) & Chr(8) ;we'll say someone meant to delete the last three characters. MsgBox(0, "Original text", $text) ;show the original text. MsgBox(0, "BS(text)", BS($text)) ;show the fixed text Func BS($String) Local $sRet = "" If StringLen($String) < 2 Then Return 0 $String = StringSplit($String, "") For $i = 1 To $String[0] If $String[$i] <> Chr(8) Then $sRet &= $String[$i];check each character for the backspace character Else $sRet = StringTrimRight($sRet, 1) EndIf Next Return $sRet ;return the fixed string. EndFunc ;==>BS ;or ;======================================================================= $TextModified = StringRegExpReplace($text, "([^\x08]\x08)", "") ; Will not replace two BS next to each other. While StringInStr($TextModified, Chr(0x08)) $TextModified = StringRegExpReplace($TextModified, "([^\x08]\x08)", "") ; Replace anything and BS with nothing. Sleep(10) WEnd MsgBox(0, "RegExp", $TextModified) ;======================================================================== MsgBox(0, "Original text", $text) Success! Thank you! 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