473,396 Members | 1,766 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,396 software developers and data experts.

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 8453
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: prasanna.hariharan | last post by:
Hi guys, I want to remove certain words from a c++ string. The list of words are in a file with each word in a new line. I tried using the std::transform, but it dint work. Anybody got a clue...
3
by: kangoo | last post by:
Hi, I'm trying to remove the last charater in a richTextBox. I though richTextBox.Text.Remove(richTextBox.Text.length-1, 1); would work, but it does nothing (eg richTextBox.Text += "some new...
0
by: talon83 | last post by:
Ok, I am wondering how do I set the amount of characters per line that a richtextbox will have. I have a save dialog code and i want to set the characters to 64 characters then goto another line and...
3
by: Paul | last post by:
Hi, My RichTextBox has multiple lines of text. Most of the lines unfortunately end with a space. Is it possible to replace the space and NewLine/Line Feed with just the NewLine/LineFeed? So...
4
by: Franky | last post by:
What I want to do is delete the last line in a RichTextBox. The RichTextBox has a ReadOnly property called lines that seems like it might help but I cant figure out how to use it. Well, the...
3
by: Bruce | last post by:
The ComboBox has a context menu with an option to "Show Unicode Control Characters". How can I use that context menu in a RichTextBox or call that functionality from a RichTextBox? Is there a way...
15
by: morleyc | last post by:
Hi, i would like to remove a number of characters from my string (\t \r \n which are throughout the string), i know regex can do this but i have no idea how. Any pointers much appreciated. Chris
26
by: Brad | last post by:
I'm writing a function to remove certain characters from strings. For example, I often get strings with commas... they look like this: "12,384" I'd like to take that string, remove the comma...
4
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, I have a multiline RichTextBox that I use for data logging. I'm concerned about how the AppendText method reacts when over time the maximum number of characters have been added. Do the...
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: 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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.