#1
|
||||
|
||||
Example: Reveal Non-printing Characters
Ever copied something to the clipboard and thought you knew what was there only to realize that there's something else present that you cannot "see"?
Or, perhaps you're working with a regular expression and the contents of the string you're working with doesn't seem to match the pattern for some reason? This example script is designed to work in SecureCRT (you map it to a button on SecureCRT's button bar) such that non-printing characters that aren't otherwise easily seen/detected can be revealed. Here's an example of the script in action, working on the clipboard text which contains double-quotes, Line Feed (ASCII Dec 10) and Carriage Return (ASCII Dec 13) non-printing characters. Here's the script code: Code:
' RevealNonPrintingCharacters.vbs ' ' Description: ' Shows one way to reveal what non-printing characters are in a string (for ' example a string that was read in from the remote that might contain ' CR, LF, and other non-printing characters and escape sequences) '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Sub Main() ' Get text from the clipboard into a variable strClipboard = crt.Clipboard.Text ' Now call the RevealNonPrintingCharacters() function, which will return ' text converted into viewable values like [CR] for a carriage return: strNonPrintingMadeVisible = RevealNonPrintingCharacters(strClipboard) ' Now, Let's show what's in that variable named "strNonPrintingMadeVisible" crt.Dialog.MessageBox strNonPrintingMadeVisible End Sub '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Function RevealNonPrintingCharacters(strText) Set colCharNames = CreateObject("Scripting.Dictionary") colCharNames.Add 0, "[NUL]" colCharNames.Add 1, "[SOH]" colCharNames.Add 2, "[STX]" colCharNames.Add 3, "[ETX]" colCharNames.Add 4, "[EOT]" colCharNames.Add 5, "[ENQ]" colCharNames.Add 6, "[ACK]" colCharNames.Add 7, "[BEL]" colCharNames.Add 8, "[BS]" colCharNames.Add 9, "[HT]" colCharNames.Add 10, "[LF]" colCharNames.Add 11, "[VT]" colCharNames.Add 12, "[FF]" colCharNames.Add 13, "[CR]" colCharNames.Add 14, "[SO]" colCharNames.Add 15, "[SI]" colCharNames.Add 16, "[DLE]" colCharNames.Add 17, "[DC1]" colCharNames.Add 18, "[DC2]" colCharNames.Add 19, "[DC3]" colCharNames.Add 20, "[DC4]" colCharNames.Add 21, "[NAK]" colCharNames.Add 22, "[SYN]" colCharNames.Add 23, "[ETB]" colCharNames.Add 24, "[CAN]" colCharNames.Add 25, "[EM]" colCharNames.Add 26, "[SUB]" colCharNames.Add 27, "[ESC]" colCharNames.Add 28, "[FS]" colCharNames.Add 29, "[GS]" colCharNames.Add 30, "[RS]" colCharNames.Add 31, "[US]" For nIndex = 32 To 126 colCharNames.Add nIndex, chr(nIndex) Next colCharNames.Add 127, "[DEL]" strRevealingText = "" For nPos = 1 To Len(strText) ' Get the current character (we're working left->right from the first ' character of the string to the last charcter of the string): strCurrentChar = Mid(strText, nPos, 1) ' Map the current character to a printable sequence (using either the ' actual character (if printable), or a substitute as defined in the ' colCharNames collection above: strRevealingText = strRevealingText & colCharNames(ASC(strCurrentChar)) Next ' Tidy things up a bit so that they'll appear more "normalized" in the ' messagebox strRevealingText = Replace(strRevealingText, "[CR][LF]", "[CRLF]" & vbcrlf) strRevealingText = Replace(strRevealingText, "[CR]", "[CR]" & vbcr) strRevealingText = Replace(strRevealingText, "[LF]", "[LF]" & vblf) strRevealingText = Replace(strRevealingText, "[HT]", "[HT]" & vbtab) RevealNonPrintingCharacters = strRevealingText End Function
__________________
Jake Devenport VanDyke Software Technical Support YouTube Channel: https://www.youtube.com/vandykesoftware Email: support@vandyke.com Web: https://www.vandyke.com/support |
![]() |
Tags |
example script |
Thread Tools | |
Display Modes | Rate This Thread |
|
|