2.6.5 String Arrays

This example shows how to create a string array, add elements to it, sort, and list the contents of the array.

// Import an existing sample file
fpath$ = "Samples\Data Manipulation\US Metropolitan Area Population.dat";
string fname$ = system.path.program$ + fpath$;

// Loop over last column and find all states
range rMetro=4;
stringarray saStates;
for( int ir=1; ir<=rMetro.GetSize(); ir++ )
	string strCell$ = rMetro[ir]$;
	string strState$ = strCell.GetToken(2,',')$;
	// Find instances of '-' in name
	int nn = strState.GetNumTokens("-");
	// Add to States string array
	for( int ii=1; ii<=nn; ii++ )
		string str$ = strState.GetToken(ii, '-')$;
		// Add if not already present
		int nFind = saStates.Find(str$);
		if( nFind < 1 )

// Sort States string array and print out
for(int ii=1; ii<=saStates.GetSize(); ii++)