Language: Add RemoveInvalidCharacters function
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
Imports System.Drawing
|
||||
Imports System.Text
|
||||
Imports System.Text.RegularExpressions
|
||||
Imports System.Windows.Forms
|
||||
''' <summary>
|
||||
''' Provides common utility functions that do not require a specific context.
|
||||
@@ -105,6 +106,38 @@ Public Class Utils
|
||||
Return oBuilder.ToString()
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Removes Invalid characters from a string, suitable for file and path names
|
||||
'''
|
||||
''' Removed characters are:
|
||||
'''
|
||||
''' * Illegal File-characters
|
||||
''' * Illegal Path-characters
|
||||
''' * Unicode characters that classify as Emoji
|
||||
''' * All characters above codepoint U+10000
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Shared Function RemoveInvalidCharacters(pString As String) As String
|
||||
Dim oResult = pString
|
||||
|
||||
' Remove all Unicode above Codepoint U+10000
|
||||
oResult = Regex.Replace(oResult, InvalidChars.UnicodeSurrogates, String.Empty)
|
||||
|
||||
' Remove all Emojis (Version 13)
|
||||
oResult = Regex.Replace(oResult, InvalidChars.Emojis, String.Empty)
|
||||
|
||||
' Remove Invalid filename characters
|
||||
oResult = Regex.Replace(oResult, InvalidChars.Filenames, String.Empty)
|
||||
|
||||
' Remove Invalid filename characters
|
||||
oResult = Regex.Replace(oResult, InvalidChars.Paths, String.Empty)
|
||||
|
||||
' Remove excess space chars
|
||||
oResult = oResult.Trim()
|
||||
|
||||
Return oResult
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Checks if a point is Visible on any screen
|
||||
''' </summary>
|
||||
|
||||
Reference in New Issue
Block a user