ライブラリ

fString_Visualize

***************************************************************
デバッグ用。
[?]や[・]等と表示されたり, 表示されない制御文字を
見えるようあぶり出す。
例:タブを『[Tab]』と表示

【引数】Value :対象の文字列
***************************************************************

Public Function fString_Visualize(Value As String) As String
'制御文字や、目視不能な文字列を、目視可能にする
    
    If Value = "" Then Exit Function
    
    Static Dic  As Scripting.Dictionary
    If Dic Is Nothing Then
        Set Dic = prDic_Unvisible
    End If
    
    Dim Vals()  As String
    ReDim Vals(1 To Len(Value))
    
    Dim i   As Long
    For i = LBound(Vals, 1) To UBound(Vals, 1)
        
        Dim Char As String
        Char = Mid$(Value, i, 1)
        
        If Dic.Exists(Char) = True Then
            Vals(i) = Dic.Item(Char)
        Else
            Vals(i) = Char
        End If
        
    Next
    
    fString_Visualize = Join(Vals, "")
    
End Function

Private Function prDic_Unvisible() As Scripting.Dictionary
    
    Dim Dic As Scripting.Dictionary
    Set Dic = New Scripting.Dictionary
    
    Dim i   As Long
    For i = 0 To 128
        
        Dim Char    As String
        Char = Chr(i)
        
        Dim View    As String
        View = ""
        Select Case Char
        Case Chr(0):    View = "[NullChar]"
        Case Chr(1):    View = "[Start Of Heading]"
        Case Chr(2):    View = "[Start Of Text]"
        Case Chr(3):    View = "[End Of Text]"
        Case Chr(4):    View = "[End Of Transmission]"
        Case Chr(5):    View = "[Enquery]"
        Case Chr(6):    View = "[Acknowledgement]"
        Case Chr(7):    View = "[Bell]"
        Case Chr(8):    View = "[Back Space]"
        Case Chr(9):    View = "[Tab]"
        Case Chr(10):   View = "[Lf]"
        Case Chr(11):   View = "[VerticalTab]"
        Case Chr(12):   View = "[FormFeed]"
        Case Chr(13):   View = "[Cr]"
        Case Chr(14):   View = "[Shift Out]"
        Case Chr(15):   View = "[Shift In]"
        Case Chr(16):   View = "[Data Link Escape]"
        Case Chr(17):   View = "[Device Control 1]"
        Case Chr(18):   View = "[Device Control 2]"
        Case Chr(19):   View = "[Device Control 3]"
        Case Chr(20):   View = "[Device Control 4]"
        Case Chr(21):   View = "[Negative Acknowledgement]"
        Case Chr(22):   View = "[Synchronous idle]"
        Case Chr(23):   View = "[End of Transmission Block]"
        Case Chr(24):   View = "[Cancel]"
        Case Chr(25):   View = "[End of Medium]"
        Case Chr(26):   View = "[End Of File]"
        Case Chr(27):   View = "[Escape]"
        Case Chr(28):   View = "[File Sepalator]"
        Case Chr(29):   View = "[Group Sepalator]"
        Case Chr(30):   View = "[Record Sepalator]"
        Case Chr(31):   View = "[Unit Sepalator]"
        Case Chr(32):   View = "[SpaceN]"
        Case " ":      View = "[SpaceW]"
        Case Chr(127):  View = "[Delete]"
        Case Chr(128):  View = "[Chr(128)]"
        End Select
        
        If View <> "" Then
            Dic.Item(Char) = View
        End If
        
    Next
    
    Dim NBSP(0 To 1) As Byte
    NBSP(0) = 160
    NBSP(1) = 0
    Dic.Item(CStr(NBSP)) = "[Non Break Space]"
    
    'ゼロ幅スペース
    Dim ZWSP(0 To 1) As Byte
    ZWSP(0) = 11
    ZWSP(1) = 32
    Dic.Item(CStr(ZWSP)) = "[Zero Width Space]"
    
    Set prDic_Unvisible = Dic
    
End Function

Public Function fString_Trim_NonBreakSpace(Value As String, Optional ReplaceVal As String = " ") As String
'HTMLに含まれる不明なスペース[?]を除去する
'※上記の[?]はAscでは[63]を返すが、「?」とは異なる値(Non Break Space)
'※HTMLのソースでは「&nbsp;」と記載
    
    Dim NBSP(0 To 1)    As Byte
    NBSP(0) = 160
    NBSP(1) = 0
    fString_Trim_NonBreakSpace = Replace(Value, CStr(NBSP), ReplaceVal)
    
End Function

Public Function fString_Trim_ZeroWidthSpace(Value As String, Optional ReplaceVal As String = "") As String
'HTMLに含まれる不明なゼロ幅スペース[?]を除去する
'※上記の[?]はAscでは[63]を返すが、「?」とは異なる値(Zero Width Space)
'※HTMLの検証では「&#8203;」と記載
    
    'ゼロ幅スペース
    Dim ZWSP(0 To 1) As Byte
    ZWSP(0) = 11
    ZWSP(1) = 32
    fString_Trim_ZeroWidthSpace = Replace(Value, CStr(ZWSP), ReplaceVal)
    
End Function
 

String   2017/11/21   shono

この記事へのコメント

コメントを送る

 
※ メールは公開されません
Loading...
 画像の文字を入力してください