110,534
社区成员
发帖
与我相关
我的任务
分享
var g = new int[1000];
int i99 = 0;
foreach (var r in File.ReadAllLines("a.txt"))
{
foreach (var x in r.Split(','))
{
g[i99++] = int.Parse(x);
}
}
还可以这样 var s = File.ReadAllText("a.txt");
var a = Regex.Matches(s, @"(?s)\d+").Cast<Match>().Select(x => int.Parse(x.Value)).ToArray();
using System;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
byte[] Byte;
using (FileStream file =new FileStream("d:\\a.txt", FileMode.Open))
{
int len = (int)file.Length;
Byte = new byte[len];
file.Read(Byte, 0, Byte.Length);
}
string str = System.Text.Encoding.UTF8.GetString(Byte);
//str= str.Replace("\r\n","");//如果不换行就取消这个批注
int i;
for (i=0; str.IndexOf(",") > 0;i++)
{
string str1 = str.Substring(0, str.IndexOf(","));
Console.Write(str1+" ");
str = str.Substring(str.IndexOf(",") + 1);
}
Console.Write("\r\n");
Console.Write(i.ToString());
Console.ReadKey();
}
}
}
额 我又整理了下代码using System;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
byte[] Byte;
using (FileStream file =new FileStream("d:\\a.txt", FileMode.Open))
{
int len = (int)file.Length;
Byte = new byte[len];
file.Read(Byte, 0, Byte.Length);
}
string str = System.Text.Encoding.UTF8.GetString(Byte);
//str= str.Replace("\r\n","");//如果不换行就取消这个批注
int[] g = new int[1000];
for (int i=0; str.IndexOf(",") > 0;i++)
{
string str1 = str.Substring(0, str.IndexOf(","));
Console.Write(str1+" ");
str = str.Substring(str.IndexOf(",") + 1);
}
Console.ReadKey();
}
}
}
这个是你要的意思吗