讀取網上TXT檔案問題

sichon
請問我在網上讀取txt,但內容格式像下面圖片,下面圖片除了藍色的數字不會改變,其他資料都會改變,字的數量也不同,請問怎樣讀取完整紅色和綠色的內容
["812300", 13.0, "", "3", 22.302, 114.174, "6", "Cloudy"],
["4415200", 12.1, "", "3", 23.03430058, 112.478027, "72", "Sunny Periods with A Few Showers"],
["44023100", 8.0, "", "3", 23.11667, 113.25, "72", "Rain],
["241300", 10.0, "", "2", 23.11147, 114.41523, "71", "Showers"],
["4450600", 9.0, "", "3", 23.02677, 113.13148, "72", "Thundery showers"],
["441900", 9.0, "", "3", 23.04889, 113.74472, "72", "Mainly Cloudly"],
["4542000", 11.0, "", "3", 22.517585, 113.39277, "72", "Mainly Fine"],
["440300", 12.0, "", "3", 22.527844, 114.0490723, "72", "Hail"],
["46640700", 10.0, "", "8", 22.560869, 113.08333, "77", "Sandstorm"],
["120400", 13.2, "", "2", 22.217308, 113.538, "71", "Showers"],



        private void Form1_Load(object sender, EventArgs e)
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            WebClient wc = new WebClient();
            string data = wc.DownloadString("https://www.123.net/123.txt");
            
            webBrowser3.DocumentText = data;
        }

最有價值解答

春天
	class Program
	{
		static void Main(string[] args)
		{
			string data = @"[""812300"", 13.0, """", ""3"", 22.302, 114.174, ""6"", ""Cloudy""],
[""4415200"", 12.1, """", ""3"", 23.03430058, 112.478027, ""72"", ""Sunny Periods with A Few Showers""],
[""44023100"", 8.0, """", ""3"", 23.11667, 113.25, ""72"", ""Rain],
[""241300"", 10.0, """", ""2"", 23.11147, 114.41523, ""71"", ""Showers""],
[""4450600"", 9.0, """", ""3"", 23.02677, 113.13148, ""72"", ""Thundery showers""],
[""441900"", 9.0, """", ""3"", 23.04889, 113.74472, ""72"", ""Mainly Cloudly""],
[""4542000"", 11.0, """", ""3"", 22.517585, 113.39277, ""72"", ""Mainly Fine""],
[""440300"", 12.0, """", ""3"", 22.527844, 114.0490723, ""72"", ""Hail""],
[""46640700"", 10.0, """", ""8"", 22.560869, 113.08333, ""77"", ""Sandstorm""],
[""120400"", 13.2, """", ""2"", 22.217308, 113.538, ""71"", ""Showers""],";

			//切成一筆一筆
			string[] lines = data.Split('\n');
			//想要的欄位,變數名稱要改成有意義命名
			const int index0 = 0;
			const int index6 = 6;
			const int index7 = 7;

			for (int i = 0; i < lines.Length; i++)
			{
				//除去多餘字元
				string lineData = lines[i].TrimEnd('\r').TrimEnd(',').TrimStart('[').TrimEnd(']');
				//切成cell
				string[] cells = lineData.Split(',');

				StringBuilder stringBuilder = new StringBuilder();

				string lineIndex = i.ToString().PadLeft(2, '0');

				stringBuilder.Append($"第{lineIndex}行:");

				for (int j = 0; j < cells.Length; j++)
				{
					switch (j)
					{
						case index0:
						case index6:
						case index7:
							string cellIndex = j.ToString().PadLeft(2, '0');
							string cellData = cells[j];
							stringBuilder.Append($"第{cellIndex}格是{cellData}, ");
							break;
						default:
							break;
					}
				}

				Console.WriteLine(stringBuilder.ToString().TrimEnd(' ').TrimEnd(','));
			}

			Console.ReadLine();
		}
	}

sichon
可以了,謝謝你
回到頂部