0
我正面临着一个非常有趣的问题。 以下是我想从中获取子字符串的字符串。泰语语言的子串
1¨Ñ§ËÇÑ´1xxxxxxxx
指数0-2(长度3)是省ID 指数3-35(长度32)是在泰国的省名。
当我试图采取子串全省像下面
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
整个字符串的长度是33.你正在做'子字符串(3,32)'这将超过33个字符,因此错误。 – Oded 2013-04-09 09:37:15
你不能使用'Substring(3)'把所有东西都弄到底吗? – 2013-04-09 09:37:26
但是,当我数我的字符串,我给它有35长度。只要看一下“1?s?s?1xxxxxxxx”中有多少个字符。我在哪里宣布字符串。 – 2013-04-09 09:42:36