I have some script that I need to implement that read certain text file for the content line by line and output accordingly.
This script to read line by line were copied from an example in wiki. Excerpt is as below:
if ( [/file get [/file find name=text.txt] size] > 0 ) do={
:global content [/file get [/file find name="text.txt"] contents] ;
:global contentLen [ :len $content ] ;
:global lineEnd 0;
:global line "";
:global lastEnd 0;
:do {
:set lineEnd [:find $content "\n" $lastEnd ] ;
:set line [:pick $content $lastEnd $lineEnd] ;
:set lastEnd ( $lineEnd + 1 ) ;
:if ( [:pick $line 0 1] != "#" ) do={
:local entry [:pick $line 0 ($lineEnd -1) ]
:if ( [:len $entry ] > 0 ) do={
<do something>
}
}
} while ($lineEnd < $contentLen)
}
The problem is with this is as below:
- First line will have the last character truncated. For eg, myname becomes mynam.
- Subsequent lines will be read fine.
Any solution to fix this issue?