[quoted text, click to view] On Feb 1, 11:24=A0am, kru <krus...@gmail.com> wrote:
> 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, _
> =A0_
> =A0Optional ByRef changeCount As Integer =3D 0) As String
> =A0 =A0 =A0 =A0 ' Create illegal character string
> =A0 =A0 =A0 =A0 Dim badChars As String =3D String.Empty
> =A0 =A0 =A0 =A0 For index As Integer =3D 0 To 31
> =A0 =A0 =A0 =A0 =A0 =A0 ' Use ChrW instead of Chr to avoid boxing
> =A0 =A0 =A0 =A0 =A0 =A0 badChars &=3D ChrW(index)
> =A0 =A0 =A0 =A0 Next
>
> =A0 =A0 =A0 =A0 ' Build RegEx pattern - square brackets say match any
> =A0 =A0 =A0 =A0 ' one of them
> =A0 =A0 =A0 =A0 Dim pattern As String =3D "[" & badChars & "]"
>
> =A0 =A0 =A0 =A0 ' Are there any illegal characters
> =A0 =A0 =A0 =A0 If Regex.IsMatch(textToCleanse, pattern) Then
> =A0 =A0 =A0 =A0 =A0 =A0 ' Count them
> =A0 =A0 =A0 =A0 =A0 =A0 changeCount =3D Regex.Matches(textToCleanse, _
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 pattern).Count
> =A0 =A0 =A0 =A0 =A0 =A0 ' Convert them to spaces
> =A0 =A0 =A0 =A0 =A0 =A0 textToCleanse =3D Regex.Replace(textToCleanse, _
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 pattern, " ")
> =A0 =A0 =A0 =A0 End If
> =A0 =A0 =A0 =A0 Return textToCleanse
> =A0 =A0 End Function
>
> Does anyone know how to resolve this issue? Any guidance would be much
> appreciated.
>
> Thanks & regards,
> Kru
Apologies all have found the issue and the above works fine, had an