winform.listview.clear(); var x = 1; for line in io.lines("C:\Users\Administrator\Desktop\aaa.txt") { //采取分行迭代方法读取 test.txt文本的内容; var a,b = table.unpack(string.split(line,"< >")); //string.split以“ ”为分割符分割读取的文本行 然后把分开的值分别赋值给a,b,模式匹配详细请参考帮助文档和论坛; winform.listview.addItem({tostring(x);a;b;});//显示到listview控件; x++; }
winform.show() win.loopMessage();
3、查找txt内文本的最大行数
io.open();//打开控制台 var lines = 0; for line in io.lines("C:\Users\Administrator\Desktop\aaa.txt") { lines++; } io.print("您输入的是" ,lines ); execute("pause") //按任意键继续
4、这个代码就有意思了,上面读数据,最后写总行数;
import console; var lines=0 for line in io.lines("C:\Users\Administrator\Desktop\aaa.txt"){ console.log(line)//这是逐行读的总的数据 lines++ } console.log(lines)//这是总的行数 console.pause(true);
import console; var num = {} for line in io.lines("C:\Users\Administrator\Desktop\123.txt") { table.push(num,line) if( string.find(line,"李四") ){ console.log("发现李四在第",#num,"行") } } execute("pause") //按任意键继续
7、找某个关键字,并找出空格前、后的数据
import console; for line in io.lines("C:\Users\Administrator\Desktop\123.txt") { var a,b = table.unpack(string.split(line,"< >")); if( string.find(line,"001") ){ console.log("找到同行空格后的数据为",b) console.log("找到同行空格前的数据为",a) } } execute("pause") //按任意键继续