Language: Add RemoveInvalidCharacters function
This commit is contained in:
8
Modules.Language/InvalidChars.vb
Normal file
8
Modules.Language/InvalidChars.vb
Normal file
File diff suppressed because one or more lines are too long
@@ -74,6 +74,7 @@
|
||||
<Import Include="System.Threading.Tasks" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="InvalidChars.vb" />
|
||||
<Compile Include="Utils.vb" />
|
||||
<Compile Include="My Project\AssemblyInfo.vb" />
|
||||
<Compile Include="My Project\Application.Designer.vb">
|
||||
|
||||
@@ -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