Txt-String is in array

From Vectorlab
Jump to: navigation, search


Function to check if a string is present in an array of string. Returns the position in the array if found. By Orso B. Schmid


{ Orso *********************************************** }
{ checks if a string is in an array of strings, returns the index or 0 }
FUNCTION T_StringIsInArray(str: STRING; arr: DYNARRAY[] OF STRING): INTEGER;
	VAR
		rowEnd, i : INTEGER;
		temp_i: INTEGER;
		
	BEGIN
		T_StringIsInArray := 0;
		GetArrayDimensions(arr, temp_i, rowEnd, temp_i, temp_i);
		
		IF rowEnd > 0 THEN BEGIN
			i := 0;
			WHILE (i < rowEnd) & (T_StringIsInArray = 0) DO BEGIN
				i := i+1;
				
				IF (str = arr[i]) THEN
					T_StringIsInArray := i;
			END;
		END;
	END;