泰语的子字符串

本文关键字:字符串 泰语 | 更新日期: 2023-09-27 18:08:26

我正面临一个非常有趣的问题。下面是我想从中取子字符串的字符串

  1¨Ñ§ËÇÑ´1xxxxxxxx                

索引0-2(长度3)为省号索引3-35(长度32)为泰语的省名。

当我尝试像下面的

那样取子字符串province时
string line = "1¨Ñ§ËÇÑ´1xxxxxxxx                ";
line.Substring(3,32).Trim();

显示如下错误

Index and length must refer to a location within the string.

请记住,当我调试代码行的总长度显示我33,应该是35。而省子字符串显示为30.

下面是代码…

        using (StreamReader streamReader = new StreamReader("File06.txt"))
        {
            Console.WriteLine(".................. Content of " + file.Name + "..............");
            string codeOfProvince, nameOfProvince, line;
            while ((line = streamReader.ReadLine()) != null)
            {
                codeOfProvince = line.Substring(0, 3).Trim();
                nameOfProvince = line.Substring(3,32).Trim();
                Console.WriteLine("codeOfProvince {0}, nameOfProvince {1}", codeOfProvince , nameOfProvince );
            }
            Console.WriteLine("..............................................................");
            Console.WriteLine();

我相信这将帮助你,文件有以下数据

  1¨Ñ§ËÇÑ´1xxxxxxxx                
  2¨Ñ§ËÇÑ´2xxxxxxxx                

泰语的子字符串

好了,我知道答案了。我正在阅读文件与ANSI编码。当我将文件更改为UNICODE编码时,它开始工作。