all groups > vb.net > january 2008 >
You're in the

vb.net

group:

String Manipulation - Multiple lines to a single line



String Manipulation - Multiple lines to a single line kru
1/31/2008 4:24:33 PM
vb.net: 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
Re: String Manipulation - Multiple lines to a single line kru
1/31/2008 4:43:46 PM
[quoted text, click to view]

Apologies all have found the issue and the above works fine, had an
AddThis Social Bookmark Button