The Translate function translates a string into a new string based on characters.
function Translate (FromChars,ToChars: string; S: string): string;
FormChars contain characters that are to be exchanged in characters from ToChars. Every single character from FromChars that occurs in string S is replaced by the character from ToChars, which is at the corresponding position.
In the simplest case FromChars contains a comma and ToChars a dot. In this case, all commas in string S are exchanged for dots.
For example, if FromChars contains the characters'ÄÖÜ' and ToChars the characters'äöü', all Ä characters in the string S are replaced by a small ä character, all Ö characters by the small ö character, and so on.
var S1: String; S2: String; begin S1:='This is 13 and this is 14'; S2:=Translate('0123456789','**********',S1); ShowMessage(s2); end;
Rules to understand the script can be found here.
The text'This is 13 and this is 14' is assigned to the string variable S1. The Translate function contains the FromChars list of characters to be searched for as the first parameter and the ToChars list as the second parameter. Since all characters are asterisks, all digits are replaced by asterisks. The result is assigned to S2.
ShowMessage shows: This is ** and this is **