Results 1 to 3 of 3

Thread: Diacritics

  1. #1

    Thread Starter
    Hyperactive Member Greyskull's Avatar
    Join Date
    Dec 2003
    Location
    somewhere in England
    Posts
    382

    Diacritics

    Hello all,

    Can anybody point me in the right direction for reading and writing diacirtics. At the moment I'm reading the data in ok, but if the data consists of diacritics, it will loose the diacritic and output some gibberish instead.

    At the moment I'm only using a normal streamreader

    i.e

    Code:
    Streamreader sr = new Streamreader(strFileName);
    
    while ( (strLine = sr.ReadLine()) != null )
    {
         //other processing goes here
    }
    Any help is greatly appreciated thanks,
    Please go to the Thread Tools menu and click Mark Thread Resolved when your post is answered
    If someone helped you today then please consider rating their post.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Diacritics

    You probably have to specify the encoding when creating the StreamReader. Read the documentation for the StreamReader class and see what constructors it has and use one that takes an Encoding as an argument. I'd start with Unicode and then try others if that doesn't work.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member Greyskull's Avatar
    Join Date
    Dec 2003
    Location
    somewhere in England
    Posts
    382

    Re: Diacritics

    Thanks for the advice,

    What I'm trying to accomplish is be able to concatenate a bunch of files and keep track of which record belong to which file by adding a field to it with the current set-up.

    I've managed to do it in this way, but I don't know how to add a field to it

    Code:
    FileStream fs = File.OpenRead(strPath);
    
                byte[] bFile = new byte[fs.Length];
    
                fs.Read(bFile, 0, (int)fs.Length);
                fs.Close();
    
                Encoding encIn = Encoding.GetEncoding(0); 
                Encoding encOut = Encoding.GetEncoding("iso-8859-1"); //I've tried UTF8 here but it didnt work :(
                byte[] decoded = Encoding.Convert(encIn, encOut, bFile, 0, bFile.Length);
    
                FileStream fOut =  File.OpenWrite(strPath);
                fOut.Write(decoded, 0, (int)decoded.Length);
                fOut.Close();
    The way I though I could do it was read one line of the file being read, append the filename where it came from, append the delimeter and then add then add the line of text that was read before re-outputting it as a new file. However, still had any luck.
    Please go to the Thread Tools menu and click Mark Thread Resolved when your post is answered
    If someone helped you today then please consider rating their post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width