Navigation: Introducing thinBasic > Example 4 |
|
This example load and scan an input file searching for lines starting with "TCC".
If any found, outputs a new file containing only such lines.
'----------------------------------------------------------------------
Uses "File"
Dim T1, T2 As Ext
Dim nLines As Long
Dim sInData As String Value File_Load( App_SourcePath + "Test_FileLineSelect(In).TXT" )
Dim sOutFile As String Value "Test_FileLineSelect(Out).TXT"
Dim sOutput As String
Dim sLines() As String
Dim Count As Long
'---Start timer
T1 = TIMER
'---Determine the number of lines
nLines = ParseCount(sInData, $CRLF)
'---This function will parse the input string for $CRLF delimiters
' filling and dimensioning sLines array
Parse sInData, sLines, $CRLF
'---Now scan the array in order to find whatever string
' If string is found, corresponding line will be appended
' to output buffer
For Count = 1 To nLines
If LEFT$(sLines(Count), 3) = "TCC" Then
sOutput = sOutput + sLines(Count) + $CRLF
End If
Next
'---Output buffer will be saved to output file
' If file exists it is overwritten
File_Save(App_SourcePath + sOutFile , sOutput)
'---End timer
T2 = Timer
'---Show total time
MsgBox 0, "Total time: " + Format$(T2 - T1, "#0.0000") + " sec"
© 2004-2008 thinBasic. All rights reserved. | Version 1.7.0.0 | Web Site: http://www.thinbasic.com |