[英]Read specific text from file
I have a text file with the following information 我有一个包含以下信息的文本文件
Caracas, 08 de Julio de 2016
SAVAKE CA
Estimado HANS AJANI
D 1089274 101548895 444.825,68 BS
i have a code that reads all the lines and prints them in the cmd: 我有一个读取所有行并将其打印在cmd中的代码:
string[] readText = File.ReadAllLines(@"p:\CARTAP1.txt");
foreach (string s in readText)
{
Console.WriteLine(s);
}
I can read the lines by using Console.WriteLine(readText[3]) but how can i get specific information in an array, for example only 1089272. 我可以使用Console.WriteLine(readText [3])读取行,但是如何获取数组中的特定信息,例如仅1089272。
How do i get those number separately instead of getting them in a line all together? 如何分别获得这些数字,而不是将它们排成一行?
By splitting the string 通过分割字符串
string input = " D 1089274 101548895 444.825,68 BS";
string result = input.Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries)[1];
Are the lines tab delimited? 线制表符是否定界? If so you can split the string 's' like so
如果是这样,您可以像这样拆分字符串“ s”
var items = s.Split('\t')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.