Txt-Substitute not in list

From Vectorlab
Jump to: navigation, search


Function to substitute chars not present in a dynarray of char with a given char. By Orso B. Schmid


{ Orso *********************************************** }
{ substitutes chars not in array from a string. }
FUNCTION T_SubstituteNotInList(str: STRING; list: DYNARRAY[] OF CHAR; newChar: CHAR): STRING;
	VAR
		i : INTEGER;
		
	BEGIN
		i := 1;
		WHILE i <= Len(str) DO BEGIN
			IF (Pos(Copy(str, i, 1), list) = 0) THEN BEGIN
				Insert(newChar, str, i);
				Delete(str, i+1, 1)
			END;
			i := i + 1;
		END;
		
		T_SubstituteNotInList := str;
	END;