[英]Regex.Matches error cannot convert from char to string
我在NET4.5中有此C#代碼來讀取一個文本文件,如下所示:
1 3 10.1144881901 48.8578515599 340.2980957031 -3.9997586182 -2.0398821492 -56.6352938643
2 1 10.1137751593 48.8575005060 401.4981384277 -11.7762306910 3.4075851669 -92.5498187137
我想更改第5行編號
這是代碼
while ((line = file.ReadLine()) != null)
{
String pattern = @"(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)";
foreach (var expression in line)
foreach (Match m in Regex.Matches(expression, pattern))
{
double value = Double.Parse(m.Groups[5].Value);
}
}
我得到了這些編譯錯誤:
錯誤CS1502:“ System.Text.RegularExpressions.Regex.Matches(string,string)”的最佳重載方法匹配具有一些無效的參數
錯誤CS1503:參數1:無法從'char'轉換為'string'
擺脫外在的foreach:
while ((line = file.ReadLine()) != null)
{
String pattern = @"(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)";
foreach (Match m in Regex.Matches(line, pattern))
{
double value = Double.Parse(m.Groups[5].Value);
}
}
您正在遍歷字符串,這是一個char數組。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.