如何阅读所有字符(包括0x0D 0x0A)和德语变音符号? [英] How do I read all chars (including 0x0D 0x0A) and German umlauts?

查看:95
本文介绍了如何阅读所有字符(包括0x0D 0x0A)和德语变音符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何阅读所有字符(包括0x0D 0x0A)和德语变音符号?

下面的代码效果很好...除了不读德语变音符号.

   字符串stFilename ="X.txt";
   编码sysEncoding = sysSetStreamReaderToHandleEscChars();
    System.IO.StreamReader srFile =新的System.IO.StreamReader(stFilename,sysEncoding);
    char cFlagChar ='\ x01';
   字符串stValues = stGetFileContentsIncludeEscCharsUpToFlagChar(srFile,cFlagChar);
    ...
   静态公共编码sysSetStreamReaderToHandleEscChars()
    {
    编码sysEncoding = Encoding.GetEncoding("Windows-1252");
    返回sysEncoding;
    }
    ...
   静态公共字符串stGetFileContentsIncludeEscCharsUpToFlagChar(System.IO.StreamReader srFile,char cFlagChar)
    {
    字符串stValues =";
     int iReadLength = 1;
    试试
     {
       char [] acBuf = null;
       while(srFile.Peek()> = 0)                       
       {
         acBuf =新字符[1];
         srFile.Read(acBuf,0,iReadLength);
        如果(acBuf [0] == cFlagChar)
          休息;
         stValues + =新字符串(acBuf);
       }
     }
     catch(异常例外)
     {
       MessageBox.Show(ex.Message);
     }
    返回stValues;
    }


bhs67

How do I read all chars (including 0x0D 0x0A) and German umlauts?

The following code works well ... except it does not read German umlauts.

    string stFilename = "X.txt";
    Encoding sysEncoding = sysSetStreamReaderToHandleEscChars();
    System.IO.StreamReader srFile = new System.IO.StreamReader(stFilename, sysEncoding);
    char cFlagChar = '\x01';
    string stValues = stGetFileContentsIncludeEscCharsUpToFlagChar(srFile, cFlagChar);
    ...
    static public Encoding sysSetStreamReaderToHandleEscChars()
    {
      Encoding sysEncoding = Encoding.GetEncoding("Windows-1252");
      return sysEncoding;
    }
    ...
    static public string stGetFileContentsIncludeEscCharsUpToFlagChar(System.IO.StreamReader srFile, char cFlagChar)
    {
      string stValues = "";
      int iReadLength = 1;
      try
      {
        char[] acBuf = null;
        while (srFile.Peek() >= 0)                
        {
          acBuf = new char[1];
          srFile.Read(acBuf, 0, iReadLength);
          if (acBuf[0] == cFlagChar)
            break;
          stValues += new string(acBuf);
        }
      }
      catch (Exception ex)
      {
        MessageBox.Show(ex.Message);
      }
      return stValues;
    }


bhs67

推荐答案

你好,
用这个替换您的功能.
抱歉,英语,我是巴西人.我不太流利.

Hello,
Replace your function with this one.
Sorry, English, I'm Brazilian. I do not have much fluency.

 static public string stGetFileContentsIncludeEscCharsUpToFlagChar(System.IO.StreamReader srFile, char cFlagChar)
        {
            StringBuilder stValues = new StringBuilder();
            byte[] Dados =  Encoding.Default.GetBytes(srFile.ReadToEnd());
            for (int i = 0; i < Dados.Length; ++i)
            {
                if (Dados[i] == cFlagChar)
                    break;
                stValues.Append(Encoding.Default.GetString(Dados,i,1)); 
            }
            return stValues.ToString();
        }


这篇关于如何阅读所有字符(包括0x0D 0x0A)和德语变音符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆