Welcome to the VanDyke Software Forums

Join the discussion today!

Go Back   VanDyke Software Forums > Scripting


Closed Thread
Thread Tools Rate Thread Display Modes
Old 10-13-2016, 09:29 AM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,099
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:
' 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)
    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))
    ' 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
Attached Images
File Type: png SCRT_ScriptExample_RevealNonPrintingCharacters.png (14.9 KB, 3630 views)
Attached Files
File Type: txt RevealNonPrintingCharacters.vbs.txt (3.2 KB, 1578 views)
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Closed Thread

example script

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -6. The time now is 05:39 PM.