Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Split text and save variables
#1
Hello

I want to store the text of the variable S in the variables arr [i] and arr2 [i] separately.
But I don't know the command and how to do it.

Ask for help.



output
arr[i]=
221
51
11


arr2[i]=
41
122
10





Function Function1
Code:
Copy      Help
str s =
;221 41
;51 122
;11 10

ARRAY(str) arr arr2
int i nt
nt = tok(s arr 2 " " 4|8|16|0x2000 arr2)
for(i 0 nt) 
,;out arr[i]
,out arr2[i]
#2
Macro Macro6
Code:
Copy      Help
out

str s =
;221 41
;51 122
;11 10

ARRAY(str) arr arr2 t
int i nt
nt=tok(s t -1 " []")
arr.create(nt/2)
arr2.create(nt/2)
for i 0 nt
,if(i&1) t[i].swap(arr2[i/2]); else t[i].swap(arr[i/2])

out "arr:"
out arr
out "arr2:"
out arr2

or

Macro Macro7
Code:
Copy      Help
out

str s =
;221, 41
;51, 122
;11, 10

ICsv x._create
x.FromString(s)

int i
out "arr:"
for(i 0 x.RowCount) out x.Cell(i 0)
out "arr2:"
for(i 0 x.RowCount) out x.Cell(i 1)
#3
Another method:

Macro 8
Code:
Copy      Help
out
str s =
;221 41
;51 122
;11 10

ARRAY(str) a1 a2
str line
foreach line s
,sub.SplitString line a1 a2

out "Array1:"
out a1
out ""
out "Array2:"
out a2

#sub SplitString
function str&x ARRAY(str)&a1 ARRAY(str)&a2

ARRAY(str) a
int ntok=tok(x a)
a1[]=a[0]
a2[]=a[1]


Forum Jump:


Users browsing this thread: 1 Guest(s)