Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
getFile return the number of lines (SOLVED)
#1
Hello,

I am using getFile to load file content to a string. It is also possible to return the number of lines in the file as it loads?

Function Dialog2
Code:
Copy      Help
str fileTxt n
if OpenSaveDialog(0 n "Text files[]*.txt[]Image files[]*.bmp;*.gif[]All Files[]*.*[]")
,fileTxt.getfile(n)
,if string.len(fileTxt)
,out fileTxt

str n a fileTxt
ARRAY(str) arr
int d nt inc
,,if OpenSaveDialog(0 n "Text files[]*.txt[]Image files[]*.bmp;*.gif[]All Files[]*.*[]")
,,,a=fileTxt.getfile(n)
nt = tok(a arr)
for(d 0 nt) 
,inc=inc+1
out F"The number of lines is {inc}"

UPDATE
I managed to solve this using tok. I don't feel it is a very efficient or clean solution but it is working as needed.

Thank you
Matthew
#2
Macro Macro48
Code:
Copy      Help
;; if using string
int i=numlines(fileTxt)
out i ;; number of lines stored in 'i', now just output 'i'


;; if using array
ARRAY(str) a
a[]="x"
a[]="y"
a[]="z"
_s=a

out numlines(_s) ;; contents of array 'a' has been put in string '_s', now you can output number of lines in '_s'
out a.len ;; or just directly output the number of items in array 'a'
#3
I was not aware of this function. Much easier solution.

Thank you!


Forum Jump:


Users browsing this thread: 1 Guest(s)