制表符分隔符从file.text中拆分 [英] tab delimiters spliting from file.text
本文介绍了制表符分隔符从file.text中拆分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我在file.text中有以下几行.我想阅读第-行
abc< tab> def&tab; ghi< tab> jkl
qwe< tab> oiu< tab> bhi< tab> iuy
如何逐行读取并将其放入某些变量中
帮助........
Let Suppose I have following lines in an file.text. I want to read line - line
abc <tab> def <tab> ghi <tab> jkl
qwe <tab> oiu <tab> bhi <tab> iuy
How to read the line by line and put it into some variable
Help........
推荐答案
我认为了解您是否对文件读取或字符串拆分感兴趣,或者两者都?
还要使用什么平台-.NET,MFC,STL?
I think it would be useful to know whether you''re interested in the file reading or the string splitting, or both?
Also what platform are you using - .NET, MFC, STL???
使用File.ReadAllLines返回文件的内容.
Use File.ReadAllLines to return the content of a file..
要逐行读取然后将读取的行分配给变量,请参考以下代码.
To read line by line and then assigning the read line to a variable, refer this code.
using System;
using System.IO;
class Test
{
public static void Main()
{
try
{
// Create an instance of StreamReader to read from a file.
// The using statement also closes the StreamReader.
// So no need of any dispose functionality
using (StreamReader sr = new StreamReader("TestFile.txt"))
{
string line;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
{
Console.WriteLine(line);
}
}
}
catch (Exception e)
{
// Let the user know what went wrong.
Console.WriteLine("The file could not be read:");
Console.WriteLine(e.Message);
}
}
}
希望这会有所帮助.
一切顺利.
Hope this helps.
All the best.
这篇关于制表符分隔符从file.text中拆分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文