Android Question Read and Replace Extended Ascii characters from a text file in DirAssets?

Todd Carlton

Member
Licensed User
Longtime User
Hello Community,

I write ASCII based files out through Visual Studio that I package into my B4A database app. Part of the data includes extended ASCII (CHR(128)-CHR(253))

I have added it to my project, so it is distributed in the File.DirAssets.

Thanks to the forums, I have already identified my problem. B4A wants UTF-8 and according to the testing I have been doing, my files are in "Windows-1252"

In this thread: http://www.b4x.com/android/forum/threads/read-extended-ascii-characters-from-a-text-file-return.23445/ there is a way to read Windows-1252 files into a string...

B4X:
Dim In As InputStream = File.OpenInput(File.DirAssets, "1.txt")
Dim tr As TextReader
tr.Initialize2(In, "Windows-1252")
Dim s As String = tr.ReadAll
tr.Close
Log(s)

My file though is several thousand lines that I am trying to read into a List...

B4X:
Dim Master As List
Master.Initialize
Master = File.ReadList(File.DirInternal, "Master_And.idx")

I'm then looking for a CHR() to substitute alternate text...

B4X:
Dim CT as int
Dim Linein as String

For CT = 0 To Master.Size - 1
     Linein = Master.Get(CT)
     Linein = Linein.Replace(Chr(251),"--------------------")
Next

Is there an easy way to read Windows-1252 text from File.DirAssets into a list and have the extended ASCII be replaceable with .replace ?

(Code above is simplified version of what I am trying to accomplish.)

In case there is an easier way to accomplish my task... My master file has over 90,000 lines in which I have identified almost a hundred repetitive phrases. I have the individual unique phrases stored in a list and have substituted them with extended ASCII in the master file. Based on the ASC() of the CHR() found in the string, the correct phrase is substituted for the extended ASCII in the B4A app. This will allowed me to reduce the master file size from 11mb down to a little over 2MB... my own dorkie compression.

Any help or direction - especially links to read - appreciated.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…