【发布时间】:2017-12-12 21:28:42
【问题描述】:
这是我想使用的文件数据,我对 python 更熟悉,但在这里找不到我需要的解决方案。感谢您的帮助。
价格:
一些卖“东西 1”,价格是 20 英镑
一些卖“东西 2”,价格是 40 英镑
一些卖“东西 3”,价格是 60 英镑
一些卖“东西 4”,价格是 80 英镑
有些卖“东西 5”,价格是 100 英镑
using System;
using System.IO;
namespace CalcPrices
{
internal class Program
{
private static void Main()
{
string[] lines = File.ReadAllLines(
@"C:\Users\Eggii\Desktop\code\c# katse\GoodsPrices\GoodsPrices\bin\Debug\PriceOfSoldGoods.txt");
for (int i = 0; i < lines.Length; i++)
{
string[] line = lines[i].Split();
for (int j = 0; j < line.Length; j++)
{
Console.WriteLine(line[6]);
// Output should be something like:
// 20
// 40
// 60
// 80
// 100
// because I want every 7th element in line
}
}
}
}
}
【问题讨论】:
-
尝试用空格分割。看起来像这样
string[] line = lines[i].Split(' ')