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

Missing characters after file rewrite using File.OpenText

Hi all,
Unsure if this is the best group to place this, but here it is anyway
;).
I've got a large text file that needs rewriting into a different
format, and decided to try it using C#, which usually does my
programming tricks... However, this time I've got a difference of
opinion with the result :(
In words using accents and special chars (i.e. façade [c cedilla] or
één [e acute]) the result of my efforts just omits these characters.
Not the words entirely, just those letters. (i.e. façade turns into
faade). Pretty much, my question is why? I'm probably just forgetting
to set a text-encoding variable somewhere, but I can't seem to find out
where it should go.

Algorithm: (and yes, I know it's not the most elegant solution...)
---
StreamReader input = File.OpenText("C:\\ERUIT.txt");
string fields="", values="";
ArrayList lines = new ArrayList();
string inputline = input.ReadLine();
while(inputline != null) {
if(inputline.Substring(0, 1) == "$") {
fields = fields.Substring(0, fields.Length-2);
values = values.Substring(0, values.Length-2);
lines.Add(String.Format("INSERT INTO InMagic ({0}) VALUES ({1});",
fields, values));
fields = ""; values = "";
}
else {
string tla = inputline.Substring(0, 3);
if(tla == "SUB" || tla == "ODN" || tla == "RTY" || tla == "LOG" ||
tla == "SCG" || tla == "NOT" || tla == "DAT" || tla == "SCS" || tla ==
"QAL" || tla == "MAT" || tla == "LOA" || tla == "SCP" || tla == "SID"
|| tla == "RGN" || tla == "REF" || tla == "COL" || tla == "PHG" || tla
== "MIS" || tla == "CON" || tla == "RIN" || tla == "COD" ||tla ==
"HEI" || tla == "RPN") {
if(tla == "NOT") tla = "_NOT";
fields += String.Format("{0}, ", tla);
values += String.Format("\"{0}\", ", inputline.Substring(4));
}
else {
values = values.Substring(0, values.Length-3);
values += String.Format("{0}\", ", inputline);
}
}
inputline = input.ReadLine();
}
input.Close();
StreamWriter output = File.CreateText("C:\\OutputKern.txt");
for(int i=0; i<lines.Count; i++) {
output.WriteLine(lines[i]);
}
output.Close();
---

PS: Config: WinXP having framework 1.0, 1.1 and 2.0 installed using VS
2k3

Thanks for every pointer anyone can give me,

Chris

Feb 17 '06 #1
1 2601
Zark3 <Za******@gmail.com> wrote:
Unsure if this is the best group to place this, but here it is anyway
;).
I've got a large text file that needs rewriting into a different
format, and decided to try it using C#, which usually does my
programming tricks... However, this time I've got a difference of
opinion with the result :(
In words using accents and special chars (i.e. façade [c cedilla] or
één [e acute]) the result of my efforts just omits these characters.
Not the words entirely, just those letters. (i.e. façade turns into
faade). Pretty much, my question is why? I'm probably just forgetting
to set a text-encoding variable somewhere, but I can't seem to find out
where it should go.


If your input file isn't in UTF-8, you should specify the encoding when
you create your StreamReader.

If your output file isn't meant to be UTF-8, you should specify the
encoding when you create your StreamWriter.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 18 '06 #2

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

Similar topics

9
by: Jon Davis | last post by:
I have a problem with encoding, I think (??). I have the following code: StreamWriter sw = File.CreateText(l); sw.Write(data); sw.Close(); Now, "data" is a string that contains text, but...
5
by: ad | last post by:
I want to delete some text which begin with <!DOCTYPE and end with > in a file. How can I do it?
14
by: tshad | last post by:
I am trying to set up a reusable library (business component) that I can use in a bunch of my pages. I built the file and it almost compiles, but I am not sure what I am missing. The vbc...
1
by: Chip | last post by:
I was under the impression that all the string and file handling methods in vb.net defaulted to UTF-8. I am losing chars and I don't know why. Dim fs As New FileStream(MyFilename, FileMode.Open,...
5
by: Marcos Ribeiro | last post by:
Hi I'm trying to read a textfile using System.IO.StreamReader, but all accentuated characters are skiped. Why's that? There is any workaround? Thanks Marcos
14
by: mesterak | last post by:
I want to very quickly count the number of lines in text files without having to read each line and increment a counter. I am working in VB.NET and C#. Does anyone have a very fast example on how...
4
by: Rob | last post by:
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...
11
by: honguin | last post by:
Hi, With the following code, I have created a web request to a url which I am making a HTML POST with the html page request.htm, even though it makes a HTML POST, the StreamReader produces a XML...
6
by: =?Utf-8?B?TUNI?= | last post by:
I try to open a log file that is logging infomation by another process: StreamReader sr = File.OpenText(filePath); I got the exception message: The process cannot access the file...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
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
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...

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.