Oxygen Basic
Programming => Problems & Solutions => Topic started by: jcfuller on April 27, 2018, 06:36:58 AM
-
Charles,
I had an issue with expanding your StringArray Class example by trying to add many more items using line continuation "_" while in a function. Is there a limit?
Also would you post an example of using your TextArray class.
Thank you.
James
-
Hi James,
Line continuation underscores should not be a problem. But they are not necessary. It is sufficient to end the line with a comma or operator, then the parser will continue onto the next line.
A very simple example using StringArray:
uses stringutil
StringArray s
string t="
four
one
two
three
Four
five
9
8
7
"
s.lines t
'case insensitive sorts:
s.sortlines
print "ascending sort:" cr s.lines
s.sortlines 1
print "descending sort" cr s.lines
A derived class with dynamic object
uses StringUtil
Class FilterTextArray
'====================
'
has TextArray
'
method LeftFilter(string k) as string
string s,u
sys i,e=mx
for i = 1 to e
s=line i
if left(s,2)=k then
u+=s+cr
end if
next
return u
end method
'
end class
'TEST
new FilterTextArray t
t.Lines quote """
% one
two
% three
% four
five
% six
"""
print "unsorted>>" cr t.lines
t.sortlines
print "sorted>>" cr t.lines
print "filtered>>" cr t.LeftFilter("% ")
del t
There was a problem in oxygen.dll affecting print t.LeftFilter ...
https://github.com/Charles-Pegge/OxygenBasic/blob/master/OxygenProgress.zip
-
Wow, O2 is so flexible to use
Charles, you are a maestro
-
Charles,
Is there an issue or did I do something wrong?
James
use rtl64
#autodim off
use console
use corewin
use stringutil.inc
string t="
four
one
two
three
Four
five
9
8
7
"
'==============================================================================
Sub CreateArray()
Print "Creating Array" cr
StringArray sa
sa.lines t
Print sa.line(1)
End Sub
'==============================================================================
Function main() As sys
CreateArray()
pause
End Function
'==============================================================================
main()
end
-
Charles,
This shows the issue more clearly. Indexes are 2 -> 10 instead of 1 to 9
James
use rtl64
#autodim off
use console
use corewin
use stringutil.inc
string t="
four
one
two
three
Four
five
9
8
7
"
'==============================================================================
Sub CreateArray()
int i,lines
Print "Creating Array" cr
StringArray sa
lines = sa.lines(t)
For i = 1 To lines
print "index " i " = " sa.line(i) cr
Next
End Sub
'==============================================================================
Function main() As sys
CreateArray()
pause
End Function
'==============================================================================
main()
end
-
Hi James,
The first line is actually a blank cr, due to the start of the multiline string. So the result is correct.