Archive for the 'string' Tag

VB Net - Convert String to Hex/Hex to String

Function StringToHex(ByVal text As String) As String
Dim hex As String
For i As Integer = 0 To text.Length - 1
hex &= Asc(text.Substring(i, 1)).ToString(”x”).ToUpper
Next
Return hex
End Function
Function HexToString(ByVal hex As String) As String
Dim text As New System.Text.StringBuilder(hex.Length \ 2)
For i As Integer = 0 To hex.Length - 2 Step 2
text.Append(Chr(Convert.ToByte(hex.Substring(i, 2), 16)))
Next
Return text.ToString
End Function

VB Net - Flip characters (Well, replace)

Public Function Flip(ByVal str As String) As String
Dim strs As String = “”
For Each cha As Char In str.ToLower
If cha = “a” Then : cha = “ɐ”
ElseIf cha = “b” Then : cha = “q”
ElseIf cha = “c” Then : cha = “ɔ”
ElseIf cha = “d” Then : cha = “p”
ElseIf cha = “e” Then : cha = “ə”
ElseIf cha = “f” Then : cha = “ɟ”
ElseIf cha = “g” Then : cha = “ɓ”
ElseIf cha = “h” Then : cha = “ɥ”
ElseIf cha = “i” Then : cha = “!”
ElseIf cha = “j” Then : cha = “ſ”
ElseIf cha = “k” Then : cha = “ʞ”
ElseIf cha = “l” Then : cha = “l”
ElseIf cha = “m” Then : cha = “ɯ”
ElseIf cha = “n” Then : cha = “u”
ElseIf cha = “o” Then : cha = “o”
ElseIf cha = “p” Then : cha = “d”
ElseIf cha = “q” Then : cha = “Ъ”
ElseIf cha = “r” Then : cha = “ɹ”
ElseIf cha = “s” Then : cha = “s”
ElseIf cha = “t” Then : cha = “ʇ”
ElseIf cha = “u” Then : cha = “n”
ElseIf cha = “v” Then : cha = “ʌ”
ElseIf cha = “w” Then : cha = “ʍ”
ElseIf cha = “x” Then : cha = “x”
ElseIf cha = “y” Then : cha = “ʎ”
ElseIf cha = “z” Then : cha = “z”
ElseIf cha = “.” Then : cha = “˙”
ElseIf cha = “_” Then : cha = “‾”
ElseIf cha = “;” Then : cha = “؛”
ElseIf cha = “!” Then : cha = “¡”
ElseIf cha = “?” Then : cha = “¿”
ElseIf cha = “‘” Then : cha = “.”
ElseIf cha = “,” Then : cha = “‘”
ElseIf cha = “_” Then : cha = “‾”
ElseIf cha = “[" Then : cha = "]“
ElseIf cha = “]” Then : cha = “["
ElseIf cha = "{" Then : cha = "}"
ElseIf cha = "}" Then : cha = "{"
ElseIf cha = "(" Then : cha = ")"
ElseIf cha = ")" Then : cha = "("
ElseIf cha = "\" Then : cha = "/"
ElseIf cha = "/" Then : cha = "\"
ElseIf cha = ControlChars.Quote Then
strs = strs & ","
cha = ","
End If
strs = strs & cha
Next
Flip = Reverse(strs)
End Function

Usage: Flip(".[i__h4x].”)  would give, ˙[x4ɥ‾‾!]˙

Note: It uses the Reverse string function that i posted in order to reverse the flipped string

VB Net - Reverse string order

    Private Function Reverse(ByVal str As String) As String
If str.Length > 1 Then
Dim val As New System.Text.StringBuilder
For pos As Int32 = str.Length - 1 To 0 Step -1
val.Append(str.Chars(pos))
Next
Return val.ToString
Else
Return str
End If
End Function

Usage: Reverse(”i__h4x”), would give x4h__i