Sunday, August 29, 2010

Encoding Strings using Escape Characters Basic

This how to encoding string using escape character. First, create new module and copy this code:

Public Function Encode(ByVal Val As String) As String
Dim i As Long, curChar As String

For i = 1 To Len(Val)
curChar = Mid(Val, i, 1)
If curChar = vbCr Then
Encode = Encode & "c"
ElseIf curChar = vbLf Then
Encode = Encode & "l"
ElseIf curChar = "" Then
Encode = Encode & "\"
Else
Encode = Encode & curChar
End If
Next i

End Function

Public Function Decode(ByVal Val As String) As String
Dim i As Long, curChar As String, EscapeMode As Boolean

For i = 1 To Len(Val)
curChar = Mid(Val, i, 1)
If EscapeMode = False Then
If curChar = "" Then
EscapeMode = True
Else
Decode = Decode & curChar
End If
Else
If curChar = "" Then
Decode = Decode & ""
ElseIf curChar = "c" Then
Decode = Decode & vbCr
ElseIf curChar = "l" Then
Decode = Decode & vbLf
End If
EscapeMode = False
End If
Next i

End Function


5 comments:

  1. Great, great post! It’s something I have never thought about, really, but it makes a whole lot of sense. Thanks for sharing

    Mazda Air Conditioner Compressor

    ReplyDelete
  2. Hey buddy that was a gud post
    lot of quality stuff and essential information

    Mazda 6 Turbo

    ReplyDelete
  3. Nice post, thanks for sharing this wonderful and useful information with us.
    Chevrolet W5500 Turbo

    ReplyDelete
  4. The blog was absolutely fantastic! Lots of great information and
    inspiration, both of which we all need!b Keep 'em coming... you all do
    such a great job at such Concepts... can't tell you how much I, for
    one appreciate all you do!

    ReplyDelete