473,799 Members | 3,339 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Tex t.ToString

Dim sr As StreamReader

sr = File.OpenText(f ilename)

Dim textstream As String = sr.ReadToEnd()

sr.Close()

Dim newtext As String

newtext = CleanHTML(texts tream)

Dim fs As New FileStream(Outp utFilename, FileMode.Create ,
FileAccess.Writ e)

Dim sw As New StreamWriter(fs )

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

sw.WriteLine(ne wtext)

sw.Close()

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

Thanks

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

When you "clean" HTML... what are you doing? Have you tried
Server.HTMLEnco de 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(f ilename)

I've replaced it with this
Dim sr As New StreamReader(fi lename, System.Text.Enc oding.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.Enc oding.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.Tex t.ToString
Remove the '.ToString' as 'txtFilename.Te xt' is already of type 'String'.
Dim sr As StreamReader

sr = File.OpenText(f ilename)

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.En coding.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
3553
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 seem to overcome, is that the english text font size my program thinks is available doesn't seem to be there. Although a line of text printed on a US Windows machine looks fine, when it is printed from this French computer the tabs are over written...
8
6448
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 doesn't look like it's working. Can anyone help please. THANK YOU.
33
4377
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. BUT
0
1520
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 a checkedListBox that holds all the directories and files that I want saved. I have two buttons (One for selecting file & one for directory) that are hooked to a openFileDialog and folderBrowserDialog. When a new file or dir is selected, it...
5
18903
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 open the file with notepad the characters are displayed correctly. e.g. in notepad: École, in Wordpad/Excel: Ã?cole. Having the user import a text file and format it themselves is not an option. The output must be .csv. The function I was...
3
3918
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() the resulting file 'Text.txt' has the same length than the string 'temp'.
1
1645
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 DropDownList with French characters.
5
6883
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 some custom formatting needed by my client. I use a StreamReader to read in the file...regular expressions to parse and clean up the file...and a StreamWriter to write the new file. On some HTML files that I parse, I get this character "á"...
0
2307
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; use warnings;
0
9687
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
9541
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
10251
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...
1
10228
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10027
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...
1
7565
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
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.