Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
rep vs forstr s ss="one[]two[][]four[]"
#1
in the help file for getl you use the following code to get each line of a var.
Code:
Copy      Help
str s ss="one[]two[][]four[]"
int i
for i 0 2000000000
    if(s.getl(ss -i)<0) break ;;no more
    if(s.len=0) continue ;;skip empty
    out s

i noticed the rep also works.
Code:
Copy      Help
str s ss="one[]two[][]four[]"
rep
    if(s.getl(ss)<0) break ;;no more
    if(s.len=0) continue ;;skip empty
    out s

would it be better to use rep since you dont need the extra var and you dont have to calc or does "for" run better in an intrinsic way?

thanks
#2
The second code is dangerous. If this getl is not the first getl in the function, it is possible that parsing does not start from the beginning.

Better use foreach:

str s ss="one[]two[][]four[]"
foreach s ss
,if(s.len=0) continue ;;skip empty
,out s


Forum Jump:


Users browsing this thread: 1 Guest(s)