Hi,
I have a text Data file with fix offset space (see below). I'm trying to insert "," into each line at a fix interval.
and save them into a new listgd.txt file for conversion into SQL database.
Below is my code using richString to insert "," but I'm not getting the result with "," in the new txt file and only the 1st line is save.
Please help. Thanks
I have a text Data file with fix offset space (see below). I'm trying to insert "," into each line at a fix interval.
B4X:
00111173 ROBERT T L+ 222 MR LLL2 31-07-12 2230 XX0322 04-08-12 0720
00111173 ROBERT T L+ 222 MR CCC6 11-08-12 2255 YY0334 15-08-12 0640
00222175 DEMI K B 333 MRS SSS1 03-07-12 1130 03-07-12 2359
00222175 DEMI K B 333 MRS SSS2 04-07-12 1130 04-07-12 2359
and save them into a new listgd.txt file for conversion into SQL database.
Below is my code using richString to insert "," but I'm not getting the result with "," in the new txt file and only the 1st line is save.
B4X:
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("main")
Dim List1 As List
'List1 = File.ReadList(File.DirDefaultExternal, "txtdata.txt")
List1.Initialize
If File.Exists(File.DirRootExternal,"txtdata.txt") Then
Dim Reader1 As TextReader
If Reader1.IsInitialized = False Then
Reader1.Initialize(File.OpenInput(File.DirRootExternal,"txtdata.txt"))
End If
Dim rs As RichString
Dim rsb As RichStringBuilder
Dim line As String
line=Reader1.ReadLine
rs.Initialize(line)
rsb.Initialize
rsb.Append(rs)
rsb.Insert(9,",")
rsb.Insert(33,",")
rsb.Insert(37,",")
rsb.Insert(42,",")
rsb.Insert(48,",")
rsb.Insert(58,",")
rsb.Insert(64,",")
rsb.Insert(75,",")
rsb.Insert(85,",")
Do While line <> Null
line = rs
List1.Add(line)
line=Reader1.ReadLine
Loop
Reader1.Close
End If
File.WriteList(File.DirRootExternal, "Listgd.txt", List1)
End Sub
Please help. Thanks