Page 1 of 1

### Example of creation big numeric arrays from text

Posted: Mon Nov 26, 2007 1:48 pm

Code: Select all

``````ARRAY_SRC = "
123 131 397397 1872 12 2 3 5 6 21 23 54 234512
1313 13  2 4 1  423 45 5 4 2 32  53  2 2 33"
CREATE_ARRAY
//Ok. Now ARRAY_RESULT - is array of numbers, described in previous lines.
//Now we can use it:
arr = ARRAY_RESULT
a = arr[ 2 ] //Now a = 131

//##############################
//SUB-PROGRAMMS FOR CONVERSION
//##############################

ARRAY_SRC = 0		//Text string like "123 456 344 223 122"
ARRAY_RESULT = 0	//Resulted numeric array

CREATE_ARRAY:
str_size = get_string_size( ARRAY_SRC )
nums = 0
n = 0
p = 0
CAR_LOOP1:
c = ARRAY_SRC[ p ]
n2 = n
if ( c >= '0' ) & ( c <= '9' ) { n = 1 } else { n = 0 }
if n = 1 & n2 = 0 { nums + 1 }
p + 1
if p < str_size { go CAR_LOOP1 }

//Create empty array:
ARRAY_RESULT = new_array( nums )
n = 0
CAR_LOOP3:
ARRAY_RESULT[ n ] = 0
n + 1
if n < nums { go CAR_LOOP3 }

//Create numbers:
n = -1
p = 0
not_a_num = 1
CAR_LOOP2:
c = ARRAY_SRC[ p ]
if ( c >= '0' ) & ( c <= '9' ) {
if not_a_num = 1 { n + 1 }
ARRAY_RESULT[ n ] = ARRAY_RESULT[ n ] * 10
ARRAY_RESULT[ n ] = ARRAY_RESULT[ n ] + ( c - '0' );
not_a_num = 0
} else { not_a_num = 1 }
p + 1
if p < str_size { go CAR_LOOP2 }
ret``````