This commit is contained in:
Digital Data - Marlon Schreiber
2017-04-18 16:08:05 +02:00
parent ca7a26beb9
commit 701cce5dff
9 changed files with 137 additions and 39 deletions

View File

@@ -1,4 +1,5 @@
Imports System.Text
Imports System.Text.RegularExpressions
Public Class ClassHelper
Public Shared Function encode_utf8(ByVal str As String) As String
@@ -9,7 +10,7 @@ Public Class ClassHelper
Dim utf8Encoding As New System.Text.UTF8Encoding(True)
Dim encodedString() As Byte
encodedString = utf8Encoding.GetBytes(str)
If LogErrorsOnly = False Then ClassLogger.Add(String.Format(" >> String {0} was encoded via utf8 to {1}", str, utf8Encoding.GetString(encodedString)))
If LogErrorsOnly = False Then ClassLogger.Add(String.Format(" >> String {0} was encoded via utf8 to {1}", str, utf8Encoding.GetString(encodedString)), False)
Return utf8Encoding.GetString(encodedString)
Catch ex As Exception
ClassLogger.Add("Unexpected error in encode_utf8: " & ex.Message)
@@ -17,4 +18,28 @@ Public Class ClassHelper
End Try
End Function
Public Shared Function StringAsUtf8Bytes(ByVal strData As String) As Byte()
Try
Dim bytes() As Byte
' get unicode string as bytes
bytes = Encoding.UTF8.GetBytes(strData)
' return byte data
Return bytes
Catch ex As Exception
ClassLogger.Add("Unexpected error in StringAsUtf8Bytes: " & ex.Message)
Return Nothing
End Try
End Function
Public Shared Function CheckSpecialSigns(ByVal str As String)
Try
Dim pattern As String = "[!""#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~\s]"
Dim matches As MatchCollection = Regex.Matches(str, pattern)
Return matches.Count
Catch ex As Exception
ClassLogger.Add("Unexpected error in CheckSpecialSigns: " & ex.Message)
Return 0
End Try
End Function
End Class