从文本文件中的一行中读取一些特定字段 [英] Read some particular field from a row in text file

查看:81
本文介绍了从文本文件中的一行中读取一些特定字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
我正在使用C#Windows基本应用程序,在该应用程序中我从文本文件中选择了特定的行,现在我只需要从该行中选择四个字段并显示在四个文本框中,其中每个字段在同一行和该行中均由制表符空格分隔有三十个字段

Hi All
I am working on C# windows base application where I selected a particular row from a text file now I have to select only four field from the row and display in four text box where every field is separated by Tab Space in the same row and that row has thirty field

推荐答案

您可以逐行阅读文本文件(请参阅 [ String.Split [
You may read the text file line by line (see "Code: Reading a Text File One Line at a Time (Visual C#)"[^]) until you hit the needed one.
Then you may use the String.Split[^] method to get requested fields.


//将整个文本框数据复制到字符串中
字符串strTextBoxData = YourTextbox.text;

string [] strSplitResult = str.Split(",StringSplitOptions.RemoveEmptyEntries);//字符串数组现在将具有按索引索引的所有数据
//whole textbox data is copied to a string
string strTextBoxData = YourTextbox.text;

string[] strSplitResult = str.Split(" ", StringSplitOptions.RemoveEmptyEntries);//string array will now have all data index by index


这篇关于从文本文件中的一行中读取一些特定字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆