labview如何读取文本文档中某一行的字符串
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了labview如何读取文本文档中某一行的字符串相关的知识,希望对你有一定的参考价值。
我在文本文档中编写一个程序,很多行,现在需要用labview获取文本文档中的某一行的字符串,例如第十行的字符串,我使用读取文本文档指令它就把所有内容全部读取了,怎么办?求教各位大神!!!可以追加悬赏!!!!
Read from Text File函数有一个count输入,表示从文本文件中读取的字节数(byte),当设置为-1时表示整个文本。此外,在函数的右键快捷菜单中选择“Read Lines”将以行为单位(而不是字节)读取文本文件。Read from Text File函数同样也提供了“Convert EOL”选项,此时该函数将把所有基于平台的行结束符转换为换行符,如将“\\r”和“\\r\\n”转换为“\\n”。
参考技术A 你要知道前面9行的字符总数,然后用设置文件位置,偏移指定的字符串,然后读取一行。很遗憾没有偏移指定行。获取文件位置有可能对你有用。本回答被提问者和网友采纳 参考技术B 使用Programing---File IO--- Read From Speedsheet.vi把txt文本读取成数组吧,之后对数组进行索引,方法比较笨,但是可以实现你的操作
c#读取文本文档实践3-写入到文本本文档
首先通过File.ReadAllLines()方法读入文本文档中内容并返回字符串数组contents,这样每行数据就成为了这个字符串数组contents的一个元素,再利用split()方法将每一个元素以空格或制表符分割,返回字符串数组,这样一行数据又被返回了3个字符串放入字符串数组中,通过Convert.ToDouble()方法将其转化为double类型并计算。创建一个StringBuilder数据类型将每行的字符串添加进去,转换为string后,最后用File.WriteAllText方法写入新建的文档。
优点是简单,缺点是只能读入小文档
,空格或制表符间隔都行
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.IO; 6 using System.Diagnostics;//Stopwatch所在命名空间 7 8 namespace 书名总价格计算 9 { 10 class Program 11 { 12 static void Main(string[] args) 13 { 14 string path = @"C:\\Users\\Administrator\\Desktop\\书名总价格计算.txt"; 15 string[] contents = File.ReadAllLines(path, Encoding.Default);//将文档所有内容放入字符串数组中 16 string[] strNew; 17 string strResult; 18 19 Stopwatch sw = new Stopwatch();//创建一个计时器方法 20 sw.Start();//开始计时 21 StringBuilder sb=new StringBuilder ();//创建sb 22 23 for (int i = 0; i < contents.Length; i++)//从第二行开始 24 { 25 if (i != 0) 26 { 27 strNew = contents[i].Split(new char[] { \' \', \'\\t\' }, StringSplitOptions.RemoveEmptyEntries); 28 Console.WriteLine("{0} {1} {2} {3}", strNew[0], strNew[1], strNew[2], Convert.ToDouble(strNew[1]) * Convert.ToDouble(strNew[2])); 29 sb.Append(strNew[0].ToString() + " " + strNew[1].ToString() + " " + strNew[2].ToString() + " " + (Convert.ToDouble(strNew[1]) * Convert.ToDouble(strNew[2])).ToString() + System.Environment.NewLine); 30 } 31 else//第一行题头不参与计算总价格 32 { 33 strNew = contents[i].Split(new char[] { \' \', \'\\t\' }, StringSplitOptions.RemoveEmptyEntries); 34 //将字符数组合并成一个字符串 35 //strResult=string.Join (" ", new string[] {strNew[0], strNew[1], strNew[2]}); 36 //strResult = string.Join(" ", strNew); 37 //Console.WriteLine(strResult); 38 Console.WriteLine("{0} {1} {2} 总价格", strNew[0], strNew[1], strNew[2]); 39 sb.Append(strNew[0].ToString() + " " + strNew[1].ToString() + " " + strNew[2].ToString() + " 总价格" + System.Environment.NewLine); 40 } 41 } 42 Console.WriteLine(sb); 43 //将sb这个字符串输出到新建的文本文档中 44 File.WriteAllText (@"C:\\Users\\Administrator\\Desktop\\书名总价格计算结果.txt", sb.ToString() ); 45 sw.Stop();//结束计时,以毫秒输出 46 Console.WriteLine(sw.ElapsedMilliseconds);//以毫秒形式输出结果 47 } 48 } 49 }
参考:http://blog.sina.com.cn/s/articlelist_2379298071_7_1.html
以上是关于labview如何读取文本文档中某一行的字符串的主要内容,如果未能解决你的问题,请参考以下文章
Javascript / Jquery识别文本文档中的每一行[重复]