Author Topic: StringArray class  (Read 1487 times)

0 Members and 1 Guest are viewing this topic.

jcfuller

  • Guest
StringArray class
« 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

Charles Pegge

  • Guest
Re: StringArray class
« Reply #1 on: April 28, 2018, 02:56:56 AM »
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:

Code: [Select]
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

Code: [Select]
 
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
« Last Edit: April 28, 2018, 03:59:39 AM by Charles Pegge »

chrisc

  • Guest
Re: StringArray class
« Reply #2 on: April 28, 2018, 05:43:47 AM »
Wow,  O2  is so flexible to use

Charles, you are a maestro

jcfuller

  • Guest
Re: StringArray class
« Reply #3 on: April 28, 2018, 06:17:42 AM »
Charles,
  Is there an issue or did I do something wrong?
James
Code: [Select]

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

jcfuller

  • Guest
Re: StringArray class
« Reply #4 on: April 28, 2018, 08:11:20 AM »
Charles,
  This shows the issue more clearly. Indexes are 2 -> 10 instead of 1 to 9
James
Code: [Select]
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

Charles Pegge

  • Guest
Re: StringArray class
« Reply #5 on: April 28, 2018, 08:24:48 AM »
Hi James,

The first line is actually a blank cr, due to the start of the multiline string. So the result is correct.