K
kru
Hi All,
Simple issue I cannot figure out.
I have a multiline textbox, I need to convert the string contents of
this textbox into a single line string which I currently write to a
textfile.
I've attempted to cleanse the contents of the textbox by removing
ASCII chars 0-31 which includes carriage returns and replacing all
ASCII chars 0-31 with a space.
Here is some code I have been using which I found online:
Public Function RemoveUnprintable(ByVal textToCleanse As String, _
_
Optional ByRef changeCount As Integer = 0) As String
' Create illegal character string
Dim badChars As String = String.Empty
For index As Integer = 0 To 31
' Use ChrW instead of Chr to avoid boxing
badChars &= ChrW(index)
Next
' Build RegEx pattern - square brackets say match any
' one of them
Dim pattern As String = "[" & badChars & "]"
' Are there any illegal characters
If Regex.IsMatch(textToCleanse, pattern) Then
' Count them
changeCount = Regex.Matches(textToCleanse, _
pattern).Count
' Convert them to spaces
textToCleanse = Regex.Replace(textToCleanse, _
pattern, " ")
End If
Return textToCleanse
End Function
Does anyone know how to resolve this issue? Any guidance would be much
appreciated.
Thanks & regards,
Kru
Simple issue I cannot figure out.
I have a multiline textbox, I need to convert the string contents of
this textbox into a single line string which I currently write to a
textfile.
I've attempted to cleanse the contents of the textbox by removing
ASCII chars 0-31 which includes carriage returns and replacing all
ASCII chars 0-31 with a space.
Here is some code I have been using which I found online:
Public Function RemoveUnprintable(ByVal textToCleanse As String, _
_
Optional ByRef changeCount As Integer = 0) As String
' Create illegal character string
Dim badChars As String = String.Empty
For index As Integer = 0 To 31
' Use ChrW instead of Chr to avoid boxing
badChars &= ChrW(index)
Next
' Build RegEx pattern - square brackets say match any
' one of them
Dim pattern As String = "[" & badChars & "]"
' Are there any illegal characters
If Regex.IsMatch(textToCleanse, pattern) Then
' Count them
changeCount = Regex.Matches(textToCleanse, _
pattern).Count
' Convert them to spaces
textToCleanse = Regex.Replace(textToCleanse, _
pattern, " ")
End If
Return textToCleanse
End Function
Does anyone know how to resolve this issue? Any guidance would be much
appreciated.
Thanks & regards,
Kru