# $language = "VBScript" # $interface = "1.0" ' 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 character 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