try:
 
 using System;
class Test{
  static void Main(){
   string s = "汉字hehe";
   Console.WriteLine(GetStringCount(s));
   Console.WriteLine(s[getRightIndex(s,7)]);
  }
  
  private static int getRightIndex(string s,int index){
    if(index <= 0) return index;
    int re = 0;
     foreach(char c in s){
       if(IsChinese(c.ToString()))
          index -= 2;
       else
          index--;
       re++;
       if(index == 0) return re;
       else 
         if(index == -1) return re - 1;
          else continue;
      }
    return -1;
  }
  
  private static int GetStringCount(string s){
   int count = 0;
   foreach(char c in s)
     if(IsChinese(c.ToString()))
       count += 2;
     else
       count++;
   return count;
  }
   private static bool IsChinese(string str) 
 {
    return (int)str[0] >= 0x4E00 && (int)str[0] <= 0x9FA5; }
 
}

解决方案 »

  1.   

    private string GetFileContents(string filePath)
    {
    System.IO.FileStream fs = System.IO.File.OpenRead(filePath);
    byte[] file = new Byte[fs.Length];
    fs.Read(file,0,Convert.ToInt32(fs.Length));
    string s = System.Text.Encoding.Default.GetString(file,0,file.Length);
    fs.Close();
    return s;
    }
      

  2.   

    //unicode解码方式下的汉字码
    array = System.Text.Encoding.Unicode.GetBytes("啊");
    i1 = (short)(array[0] - '\0');
    i2 = (short)(array[1] - '\0');//unicode反解码为汉字
    string str = "4a55";
    string s1 = str.Substring(0,2);
    string s2 = str.Substring(2,4);int t1 = Convert.ToInt32(s1,16);
    int t2 = Convert.ToInt32(s2,16);array[0] = (byte)t1;
    array[1] = (byte)t2;string s = System.Text.Encoding.Unicode.GetString(array);
      

  3.   

    trouble remains~~~~~
    用default读出来的字符串虽然没有乱码,但是位数不对了!比如
    E2WPW02                       300000000000021801500000900000803 万向配件                           01                                <-
    到箭头为止应该是134(非unicode)因为汉字有2位!
    但是用default读出来以后就变短了因为汉字只有1位了!问题回到了最初!
    在不出现乱码的情况下!汉字占2位,一行一行的读取近来!
    我都不好意思了!可是这个问题真的很难说清楚,我估计这次应该清楚了吧!
      

  4.   

    我再把问题说一边换个方式,我要读取的字符串是已知的134位!并包括汉字!为ascii!
    那么我现在在程序里要这样得到,仍然为134位!汉子正常显示。每个汉字占2个字节!
    over!
    谁来救救我?观世音,如来?上帝?