如果有一个文件如下:
TITLE = "Water Wurface Elevation"
VARIABLES = "X", "Y", "WS"
Zone N= 384016, E= 96004, DT=(DOUBLE DOUBLE SINGLE), F=FEPOINT, ET=QUADRILATERAL, T="Flow 54.000 @ 290.00 Days"
417183.062 3121115.75 25.17824
417387.938 3121108.75 25.17824
417381.781 3120930.5 25.17824
417176.844 3120937.5 25.17824
417387.938 3121108.75 25.18108
417592.625 3121101.5 25.18108
417586.438 3120923.5 25.18108
417381.781 3120930.5 25.18108
417592.625 3121101.5 25.18995
417797.031 3121094.5 25.18995
417790.688 3120916.75 25.18995
417586.438 3120923.5 25.18995
.......
135813 135814 135815 135816
135817 135818 135819 135820
135821 135822 135823 135824
135825 135826 135827 135828
135829 135830 135831 135832
135833 135834 135835 135836
135837 135838 135839 135840
135841 135842 135843 135844
135845 135846 135847 135848
......
PureBasic可以采用正则表达式来实现,读取每行中第三个数据,如果每行包含四个数据,则不保存。
读取含三个数据的每行第三个数据并保存的代码如下:
StandardFile$ = "*.plt" Pattern$ = "文本文件 (*.txt)|*.txt;所有文件 (*.*)|*.*" Pattern = 1 File$ = OpenFileRequester("请选择需要打开的文件", StandardFile$, Pattern$, Pattern) If File$ MessageRequester("信息", "你选择了:" + Chr(10) + File$, 0) If CreateRegularExpression(0, "[0-9.]+") Dim Result$(0) If OpenFile(0,File$) CreateFile(1,"c:\test.dat") Text$=ReadString(0) Text$=ReadString(0) Text$=ReadString(0) While Eof(0)=0 Text$=ReadString(0) a = ExtractRegularExpression(0,Text$, result$()) Str$=result$(2) If a=3 WriteStringN(1,Str$) EndIf Wend CloseFile(0) CloseFile(1) MessageRequester("信息", "完成了文件的输出!",0) EndIf Else MessageRequester("正则表达式有误", RegularExpressionError()) EndIf EndIf