Notifications
Clear all
[Closed] Counting lines in a string(stream)?
Oct 28, 2004 11:16 am
Hi,
I’m working on something that requires me to know the lines of text in either a string or stringStream. Right now I have this:
line_counter = 0
seek txt_whole 0
while 1 != 2 do
(
try
(
skipToNextLine txt_whole
)
catch exit
line_counter += 1
)
print ("Lines: " + (line_counter as string))
[font=Verdana]In this case txt_whole[/font] is the following stringStream:
rollout test "Untitled" width:320 height:312
(
editText edt3 "" pos:[16,32] width:288 height:112
editText edt4 "" pos:[16,184] width:288 height:112
label lbl1 "Output:" pos:[24,168] width:40 height:16
label lbl2 "Input:" pos:[24,16] width:40 height:16
button btn1 "Code it" pos:[112,152] width:88 height:24
on edt3 entered text do
global txt_test = edt3.text
But it seems to count the lines double. It returned 18 lines here…
I could divide by two or something but I wonder what the cause is and if there’s a more elegant solution.
Thanks,
- Rens
2 Replies
Oct 28, 2004 11:16 am
You could try filterString with the newline character (“
“) and get the resulting array’s .count. Seems like it should work.
RH
Oct 28, 2004 11:16 am
Hurrah!
Thanks, it works very nice. I only have one small bug to fix and then I’ll be ready to post my new script… behold…
- R