String Manipulation - Multiple lines to a single line

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
 
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

Apologies all have found the issue and the above works fine, had an
older version of the app open /slap
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top