|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Remove certain characters from a string/RichTextBox?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 Hello Paul,
Take a look at System.String -Boo Show quoteHide quote > 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 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): Show quoteHide quote > 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 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): Show quoteHide quote > 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 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" <grzesiek.mr***@gmail.com> wrote in message Maybe i'm not very clever but what about replace function?:> it can'tnews:1157489308.786190.301640@i3g2000cwc.googlegroups.com... Hi be? Imports System.Text.RegularExpressions .. .. Regex.Replace(value, "old char", "new char")) what about it?? Mrozu Paul napisal(a): Show quoteHide quote > 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 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 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 <hoffman.a***@gmail.com> wrote in message Show quoteHide quote news:1157495785.150450.217370@d34g2000cwd.googlegroups.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 > Paul wrote:
> Yes that works but it looks very bad. You can replace multiple characters with a single RegEx.Replace() call.> > I was hoping to set up an array and loop through the RichTextBox but thanks > anyway! > 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 ". Thanks Douglas, I've incorporated this into my project, had no idea about
the square brackets!" Paul Show quoteHide quote "Douglas Richard" <djrich***@gmail.com> wrote in message news:1157600193.935705.105480@d34g2000cwd.googlegroups.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 ". >
[Regular Expression] extraction when bounds are vbCr and vbLf
Better way to process many conditions with If Then How to input characters that are not present in a keyboard to a VB User Control constructors taking arguments? UI Challenge: How to create a real outliner (like Ecco, Grandview, etc) - SampleDisplay.bmp (0/1) Book Recommendations Request datagridview.SelectedRows returns last row first? Break up string, Comma Delimited Is the difference intended? Intellisense XML Comments / Documentation |
|||||||||||||||||||||||