469,569 Members | 1,577 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,569 developers. It's quick & easy.

Remove certain characters from a string/RichTextBox?

Hi,

My VB is very rusty I'm afraid! What would be the most efficient way to
remove the following ASCII characters from a string?





Y o O
*
. -

I want to load the contents of a file (which contains normal numbers &
letters aswell as the ones above) and then remove each occurance of each
unwanted character.

Preferably I want to show the contents of the file in the RichTextBox and
then press a command button to remove the ASCII characters and then update
the RichTextBox.

I just need some clever person to tell me how I can remove these horrible
characters! I'm guessing one way is setting up an array with these
characters in, then looping through the RichTextBox to seek out the
occurances of each character? If only I knew how to do this!

Thanks
Paul

Sep 5 '06 #1
8 7918
Hello Paul,

Take a look at System.String

-Boo
Hi,

My VB is very rusty I'm afraid! What would be the most efficient way
to remove the following ASCII characters from a string?





Y o O
*
. -
I want to load the contents of a file (which contains normal numbers &
letters aswell as the ones above) and then remove each occurance of
each unwanted character.

Preferably I want to show the contents of the file in the RichTextBox
and then press a command button to remove the ASCII characters and
then update the RichTextBox.

I just need some clever person to tell me how I can remove these
horrible characters! I'm guessing one way is setting up an array with
these characters in, then looping through the RichTextBox to seek out
the occurances of each character? If only I knew how to do this!

Thanks
Paul

Sep 5 '06 #2
Hi

Maybe i'm not very clever but what about replace function?:it can't
be?

Imports System.Text.RegularExpressions
..
..
Regex.Replace(value, "old char", "new char"))
what about it??

Mrozu

Paul napisal(a):
Hi,

My VB is very rusty I'm afraid! What would be the most efficient way to
remove the following ASCII characters from a string?





Y o O
*
. -

I want to load the contents of a file (which contains normal numbers &
letters aswell as the ones above) and then remove each occurance of each
unwanted character.

Preferably I want to show the contents of the file in the RichTextBox and
then press a command button to remove the ASCII characters and then update
the RichTextBox.

I just need some clever person to tell me how I can remove these horrible
characters! I'm guessing one way is setting up an array with these
characters in, then looping through the RichTextBox to seek out the
occurances of each character? If only I knew how to do this!

Thanks
Paul
Sep 5 '06 #3
Hi

Maybe i'm not very clever but what about replace function?:it can't
be?

Imports System.Text.RegularExpressions
..
..
Regex.Replace(value, "old char", "new char"))
what about it??

Mrozu

Paul napisal(a):
Hi,

My VB is very rusty I'm afraid! What would be the most efficient way to
remove the following ASCII characters from a string?





Y o O
*
. -

I want to load the contents of a file (which contains normal numbers &
letters aswell as the ones above) and then remove each occurance of each
unwanted character.

Preferably I want to show the contents of the file in the RichTextBox and
then press a command button to remove the ASCII characters and then update
the RichTextBox.

I just need some clever person to tell me how I can remove these horrible
characters! I'm guessing one way is setting up an array with these
characters in, then looping through the RichTextBox to seek out the
occurances of each character? If only I knew how to do this!

Thanks
Paul
Sep 5 '06 #4
Yes that works but it looks very bad.

I was hoping to set up an array and loop through the RichTextBox but thanks
anyway!

RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "", " ")
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "", " ")
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "", " ")
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "", " ")
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "", " ")
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "", " ")
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "", " ")
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "", " ")
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "", " ")
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "()", " ")
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "", " ")
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "", " ")
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "", " ")
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "", " ")
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "", " ")
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "", " ")
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "", " ")
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "", " ")
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "", " ")
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "", " ")
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "", " ")
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "()", " ")
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "", " ")
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "", " ")
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "", " ")
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "", " ")
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "", " ")
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "", " ")
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "", " ")
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "", " ")
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "", " ")
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "", " ")
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "", " ")
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "", " ")
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "", " ")
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "", " ")
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "", " ")
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text, "", " ")
Paul
"Mrozu" <gr************@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
Hi

Maybe i'm not very clever but what about replace function?:it can't
be?

Imports System.Text.RegularExpressions
..
..
Regex.Replace(value, "old char", "new char"))
what about it??

Mrozu

Paul napisal(a):
Hi,

My VB is very rusty I'm afraid! What would be the most efficient way to
remove the following ASCII characters from a string?





Y o O
*
. -

I want to load the contents of a file (which contains normal numbers &
letters aswell as the ones above) and then remove each occurance of each
unwanted character.

Preferably I want to show the contents of the file in the RichTextBox and
then press a command button to remove the ASCII characters and then update
the RichTextBox.

I just need some clever person to tell me how I can remove these horrible
characters! I'm guessing one way is setting up an array with these
characters in, then looping through the RichTextBox to seek out the
occurances of each character? If only I knew how to do this!

Thanks
Paul

Sep 5 '06 #5
If you have the list of the unwanted characters in a file, you could
read in the file line by line, split the line by spaces, and loop
through doing a replace that way. Something like this

Dim fs As New FileStream(YourUnwantedCharFileLoc, FileMode.Open,
FileAccess.Read)
Dim g As New StreamReader(fs)
dim numchars as integer
'make sure you start at the beginning
g.BaseStream.Seek(0, SeekOrigin.Begin)
Dim ArrayLine() As char
'while you are not at the end of the file
While g.Peek() -1
'split into chars
ArrayLine = Split(g.ReadLine(), " ")
For numchars = 0 to ArrayLine.Length
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text,
ArrayLine(numchars), " ")
next
End While

Sep 5 '06 #6

Paul wrote:
Yes that works but it looks very bad.

I was hoping to set up an array and loop through the RichTextBox but thanks
anyway!
You can replace multiple characters with a single RegEx.Replace() call.
Supply a list of all the characters you want to replace, surrounded by
square "[", "]" brackets.

the statement:

Regex.Replace("abcdefg", "[aceg]", " ")

returns the string " b d f ".

Sep 7 '06 #7
Thanks but I get a error before I'm able to compile...

Value of type '1-dimensional array of String' cannot be converted to
'1-dimensional array of Char' because 'String' is not derived from 'Char'.

It occurs on this line...
ArrayLine = Split(g.ReadLine(), " ")

Any ideas what that could mean?

Paul
<ho**********@gmail.comwrote in message
news:11**********************@d34g2000cwd.googlegr oups.com...
If you have the list of the unwanted characters in a file, you could
read in the file line by line, split the line by spaces, and loop
through doing a replace that way. Something like this

Dim fs As New FileStream(YourUnwantedCharFileLoc, FileMode.Open,
FileAccess.Read)
Dim g As New StreamReader(fs)
dim numchars as integer
'make sure you start at the beginning
g.BaseStream.Seek(0, SeekOrigin.Begin)
Dim ArrayLine() As char
'while you are not at the end of the file
While g.Peek() -1
'split into chars
ArrayLine = Split(g.ReadLine(), " ")
For numchars = 0 to ArrayLine.Length
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text,
ArrayLine(numchars), " ")
next
End While

Sep 7 '06 #8
Thanks Douglas, I've incorporated this into my project, had no idea about
the square brackets!"

Paul
"Douglas Richard" <dj*******@gmail.comwrote in message
news:11**********************@d34g2000cwd.googlegr oups.com...
>
Paul wrote:
>Yes that works but it looks very bad.

I was hoping to set up an array and loop through the RichTextBox but
thanks
anyway!

You can replace multiple characters with a single RegEx.Replace() call.
Supply a list of all the characters you want to replace, surrounded by
square "[", "]" brackets.

the statement:

Regex.Replace("abcdefg", "[aceg]", " ")

returns the string " b d f ".

Sep 7 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

18 posts views Thread by prasanna.hariharan | last post: by
3 posts views Thread by kangoo | last post: by
15 posts views Thread by morleyc | last post: by
26 posts views Thread by Brad | last post: by
4 posts views Thread by =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.