473,325 Members | 2,480 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,325 software developers and data experts.

Streamwriter removes french characters

Rob

Hi,

I have a small VB.Net program that reads in an HTML file using a
FileStream (this file was created by MS Word "Save as HTML" feature),
uses regular expressions to remove all unwanted code and then re-writes
the file.

It works fine but when I execute this on a french web page...the
StreamWriter removes all of the french characters. Here's a piece of the
code:

Dim filename As String = txtFilename.Text.ToString

Dim sr As StreamReader

sr = File.OpenText(filename)

Dim textstream As String = sr.ReadToEnd()

sr.Close()

Dim newtext As String

newtext = CleanHTML(textstream)

Dim fs As New FileStream(OutputFilename, FileMode.Create,
FileAccess.Write)

Dim sw As New StreamWriter(fs)

' I've also tried:
'Dim sw as New StreamWriter(fs, System.Text.Encoding.UTF8)

sw.WriteLine(newtext)

sw.Close()

I'm kinda new to .Net Development...does anyone see what's wrong here?

Thanks

*** Sent via Developersdex http://www.developersdex.com ***
May 24 '07 #1
4 5826
Rob <ro****@hotmail.comwrote in news:OAplhegnHHA.4552
@TK2MSFTNGP04.phx.gbl:
newtext = CleanHTML(textstream)
What does this function do? Is it stripping out french characters?

When you "clean" HTML... what are you doing? Have you tried
Server.HTMLEncode instead?
May 24 '07 #2
Rob
When I run the CleanHTML function...I remove a lot of garbage that comes
with saving a Word document as HTML. I remove all the styles, span tags
and a lot of other tags that are not needed.

When I clean up a french webpage, the StreamReader or StreamWriter
doesn't seen to understand french characters and strips them out but I
want to preserve them.

Another thing I've tried is, rather than using this line:
Dim sr As StreamReader
sr = File.OpenText(filename)

I've replaced it with this
Dim sr As New StreamReader(filename, System.Text.Encoding.Default)

but this returns strange result as well.

*** Sent via Developersdex http://www.developersdex.com ***
May 24 '07 #3
Rob
I got it.

I added System.text.Encoding.Default to my StreamWriter as well as my
StreamReader and that fixed it.

Thanks

*** Sent via Developersdex http://www.developersdex.com ***
May 24 '07 #4
"Rob" <ro****@hotmail.comschrieb:
I have a small VB.Net program that reads in an HTML file using a
FileStream (this file was created by MS Word "Save as HTML" feature),
uses regular expressions to remove all unwanted code and then re-writes
the file.

It works fine but when I execute this on a french web page...the
StreamWriter removes all of the french characters. Here's a piece of the
code:

Dim filename As String = txtFilename.Text.ToString
Remove the '.ToString' as 'txtFilename.Text' is already of type 'String'.
Dim sr As StreamReader

sr = File.OpenText(filename)

Dim textstream As String = sr.ReadToEnd()
Note that the 'StreamReader' object is initialized for the UTF-8 encoding by
default. If your file has been encoded using a different encoding, such as
Windows' default ANSI codepage, then pass 'System.Text.Encoding.Default' in
the parameter accepting an encoding of the 'StreamReader''s constructor.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

May 24 '07 #5

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

Similar topics

3
by: Salgoud Dell | last post by:
I have a VB6 application running on a French computer using Windows ME. The app doesn't work the same way as it does when running on an English Windows OS. The main issue I have, that I can't...
8
by: Beznas | last post by:
Hi All; I'm trying to create an ASP function called CleanX that removes the punctuation and some characters like (*&^%$#@!<>?"}|{..) from a text string I came up with this but It...
33
by: | last post by:
Hi, When constructing StreamWriter with the following.. FileStream f = new FileStream(..); StreamWriter s = new StreamWriter(f); Then attempt to write out åäö letters they become garbage. ...
0
by: notalent | last post by:
I'm having a problem with a very basic program. I'm creating a app in Visual Studio (2003) C# to zip up a collection of specified files & directories and save them to a certain location. I have...
5
by: Brendan Miller | last post by:
Hi, I have been having a problem writing the contents of a dataset to a .csv file. When I write to a .csv file and open it with either Excel or Wordpad the "french" characters are wrong. When I...
3
by: philip | last post by:
If I execute that : Dim Temp as string = "This is a text" Dim sw As StreamWriter Dim fullFileName as string = "c:\text.txt" sw = New StreamWriter(fullFilename) sw.Write(temp) sw.Close() ...
1
by: prasadoo | last post by:
Hi everyone, I am trying to populate DropDownList with French characters but for some characters like é,d' etc.it is not showing the exacts French characters. Can anybody help me how to populate...
5
by: Rob | last post by:
Hi, I have a VB.Net application that parses an HTML file. This file was an MS Word document that was saved as web page. My application removes all unnecessary code generated by MS Word and does...
0
by: shintu | last post by:
Hallo, I am trying to write french accented characters é è ê in Excel worksheet using my perl script , But I am stuck here as I couldnt find a way of writing it !: My code: use strict;...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.