Txt-Search replace prefix

From Vectorlab
Jump to: navigation, search


Function to search/replace a string at beginning only. Returns the resulting string. By Orso B. Schmid


{ Orso *********************************************** }
{ search replace string only first found at beginning }
{ warning! this can output an empty string! }
FUNCTION T_SearchReplacePrefix(sourceStr, searchStr, replStr: STRING): STRING;
	VAR
		ready : STRING;
	BEGIN
		T_SearchReplacePrefix := sourceStr;
		
		IF Pos(searchStr, sourceStr) = 1 THEN BEGIN
			ready := sourceStr;
			Delete(ready, 1, Len(searchStr));
			T_SearchReplacePrefix := Concat(replStr, ready);
		END;
	END;