473,774 Members | 2,094 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8571
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.Reg ularExpressions
..
..
Regex.Replace(v alue, "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.Reg ularExpressions
..
..
Regex.Replace(v alue, "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.Te xt = Regex.Replace(R ichTextBox1.Tex t, "à", " ")
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "è", " ")
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "ì", " ")
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "ò", " ")
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "ù", " ")
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "À", " ")
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "È", " ")
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "Ì", " ")
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "Ò", " ")
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "(Ù)", " ")
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "á", " ")
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "é", " ")
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "í", " ")
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "ó", " ")
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "ú", " ")
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "ý", " ")
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "Á", " ")
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "É", " ")
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "Í", " ")
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "Ó", " ")
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "Ú", " ")
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "(Ý)", " ")
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "â", " ")
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "ê", " ")
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "î", " ")
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "ô", " ")
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "û", " ")
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "Â", " ")
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "Ê", " ")
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "Î", " ")
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "Ô", " ")
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "Û", " ")
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "ã", " ")
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "ñ", " ")
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "õ", " ")
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "Ã", " ")
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "Ñ", " ")
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t, "Õ", " ")
Paul
"Mrozu" <gr************ @gmail.comwrote in message
news:11******** **************@ i3g2000cwc.goog legroups.com...
Hi

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

Imports System.Text.Reg ularExpressions
..
..
Regex.Replace(v alue, "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(Your UnwantedCharFil eLoc, FileMode.Open,
FileAccess.Read )
Dim g As New StreamReader(fs )
dim numchars as integer
'make sure you start at the beginning
g.BaseStream.Se ek(0, SeekOrigin.Begi n)
Dim ArrayLine() As char
'while you are not at the end of the file
While g.Peek() -1
'split into chars
ArrayLine = Split(g.ReadLin e(), " ")
For numchars = 0 to ArrayLine.Lengt h
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t,
ArrayLine(numch ars), " ")
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.ReadLin e(), " ")

Any ideas what that could mean?

Paul
<ho**********@g mail.comwrote in message
news:11******** **************@ d34g2000cwd.goo glegroups.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(Your UnwantedCharFil eLoc, FileMode.Open,
FileAccess.Read )
Dim g As New StreamReader(fs )
dim numchars as integer
'make sure you start at the beginning
g.BaseStream.Se ek(0, SeekOrigin.Begi n)
Dim ArrayLine() As char
'while you are not at the end of the file
While g.Peek() -1
'split into chars
ArrayLine = Split(g.ReadLin e(), " ")
For numchars = 0 to ArrayLine.Lengt h
RichTextBox1.Te xt = Regex.Replace(R ichTextBox1.Tex t,
ArrayLine(numch ars), " ")
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*******@gmai l.comwrote in message
news:11******** **************@ d34g2000cwd.goo glegroups.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
23458
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 as to how i should go about this. thanks a lot, Hp
3
21163
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 text"; works) Thanks for your attention & solutions
0
1782
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 save it like that. Right now when it saves a line of text, say 128 characters, it puts it all in 1 line. I would like it to split the line into two lines in the output .rtf file. ' Create a SaveFileDialog to request a path and file...
3
5839
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 in essence just removing the trailing space from each line?
4
5978
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 question is what is the easiest way to remove the last line in a RichTextBox? Thanks
3
6223
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 to do that. I'd be surprised if that was missing from RichTextBox and only available from a ComboBox. I could really use that with RTL Arabic text.
15
50260
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
13807
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 and return "12384" What is the most efficient, fastest way to approach this? Thanks,
4
13485
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 oldest characters it contains start rolling off the top into the bit bucket, does it simply start silently ignoring appends until some characters, are deleted, or does some kind of exception get thrown? I've heard numerous opinions on what the...
0
9621
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10267
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10106
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9914
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8939
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7463
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4012
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.