473,385 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

String Manipulation - Multiple lines to a single line

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

Feb 1 '08 #1
1 3621
kru
On Feb 1, 11:24*am, kru <krus...@gmail.comwrote:
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
Feb 1 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Roland Hall | last post by:
I'm looking for information on working with large data files using FSO, XML. I have a program which creates a large CSV file, over 7mb. It's a rate table of freight shipping costs. There are...
1
by: Robizzle | last post by:
I'm writting a script that produces html source code from form input. My problem is that I want to format my html source with new lines and tabs. So, I have a string that holds all the contents...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
5
by: Kirk Bay | last post by:
I'm trying to build an app that populates a word form. The problem I've got is when the user types more data than the field will hold, I need to take the excess and dump it onto a continuation...
20
by: bubunia2000 | last post by:
Hi all, I heard that strtok is not thread safe. So I want to write a sample program which will tokenize string without using strtok. Can I get a sample source code for the same. For exp:...
13
by: Freaker85 | last post by:
Hello, I am new at programming in C and I am searching a manner to parse a string into an integer. I know how to do it in Java, but that doesn't work in C ;o) I searched the internet but I...
6
by: kellygreer1 | last post by:
What is a good one line method for doing a "length safe" String.Substring? The VB classes offer up the old Left function so that string s = Microsoft.VisualBasic.Left("kelly",200) // s will =...
6
by: HeEm | last post by:
In my 100 level CS course, I was asked to create multiple lines of output within a single string. Of course I know how to: print "I am" print "a python" print "newbie." How can I get this...
4
by: BA | last post by:
Hello, I have a very strange code behavior that I cannot make heads or tails of: I have c# code being executed in BizTalk assemblies which is acting very strangely. In my BizTalk process I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.