[英]A C# filestream function, which should return a set of double coordinates
我讓這個函數從文本文件中返回兩個坐標和一個名稱。 一切正常,但是當我嘗試在另一個函數中使用這些坐標時,我似乎得到了兩個integers
而不是doubles
數。 下面是使用 getter 時的實際代碼和輸出。
輸入文件中的示例:
delfshaven 51.9229006954, 4.43681055082
delfshaven 51.9229377766, 4.43726467466
代碼:
public void ReadCoords(string path, string naam)
{
string line;
int endname;
int endfirstcoord;
int i;
string name;
string coord1;
string coord2;
double north, east;
var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read);
using (StreamReader reader = new StreamReader(fileStream, Encoding.ASCII))
{
while (!reader.EndOfStream)
{
line = reader.ReadLine();
if (line != "")
{
i = 0;
while (line[i] != ' ')
{
i++;
}
endname = i;
name = line.Substring(0, i);
i++;
if (naam == name)
{
while (line[i] != ',')
{
i++;
}
endfirstcoord = i;
coord1 = line.Substring(endname + 1, i - 1 - (endname));
coord2 = line.Substring(i + 2, line.Length - (i + 2));
north = double.Parse(coord1);
east = double.Parse(coord2);
deelgemeente.Add(new PointLatLng(north, east));
}
}
}
}
}
輸出:
{Lat=519226886783, Lng=443421830655}
{Lat=519227198819, Lng=443459846581}
{Lat=51922824973, Lng=443591425503}
{Lat=519228427681, Lng=443610117779}
{Lat=519229006954, Lng=443681055082}
提前致謝。
謝謝您的幫助。 我得到了修復。 由於我的本地筆記本電腦設置,出現問題。 將字符串轉換為 double 時遇到了麻煩。
north = double.Parse(coord1, CultureInfo.InvariantCulture);
east = double.Parse(coord2, CultureInfo.InvariantCulture);
代替
north = double.Parse(coord1);
east = double.Parse(coord2);
修復。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.