TRANSLATE†
Format†
TRANSLATE( text , format_from , format_to )
Function†
- Performs fast character-to-character replacement of strings.
- Equivalent to Perl's tr/// without any options.
Arguments†
- text
- The string to replace.
- format_from
- The list of characters before replacement. See "About formatting".
- format_to
- The list of characters after replacement. See "About formatting". Empty string to delete.
About formatting†
- A simple list of characters is replaced on a one-to-one basis. Characters not included in the replacement list are left as is.
- TRANSLATE('World','ld','th') -> Worth
- TRANSLATE('AAAIIIUUU','AI','OE') -> OOOEEEUUU
- Putting a "-" between the two will perform a batch replace operation within the specified character code range.
- TRANSLATE('123456789','1-9','①-⑨') -> ①②③④⑤⑥⑦⑧⑨
- The character code used is UCS-2 (Unicode), so please switch the IME character palette to Unicode mode to check it.
- If you want to write "-" itself, write "\-". If you want to write "\" itself, write "\\".
- TRANSLATE('\-\-\-','\\','\-') -> ------
- If the third argument is an empty string, it is a delete operation.
- TRANSLATE('46cm三連装砲','0-9a-z','') -> 三連装砲
Return value†
- If successful, the replaced string
- If unsuccessful, -1.
Related†
Version†
- Tc546-1
- Escape sequence added in Tc546-2
- Deletion process added in Tc547-1
Example†
Write the following script to convert hiragaka to katakana and katakana to hiragana.
Translation note: the following example is reliant on a basic understanding of Japanese text. See underneath for a similar concept in English.
_wokyu = TRANSLATE('ティータイムは大事にしないとネー','ぁ-ゖァ-ヶ','ァ-ヶぁ-ゖ')
//Contents of _wokyu = てぃーたいむハ大事ニシナイトねー
//The Unicode table specifies the overlapping range of katakana and hiragana, "ァ-ヶ"
//If you are writing a dictionary in Shift JIS, "ゖ" will be garbled, so for now, use the following.
_wokyu = TRANSLATE('ティータイムは大事にしないとネー','ぁ-んァ-ン','ァ-ンぁ-ん')
Translation note: this is an additional example provided to show how this function can be used in English. Here, it is used to swap uppercase letters and lowercase letters.
_wokyu = TRANSLATE('Tea time should be cherished','a-zA-Z','A-Za-z')
//Contents of _wokyu = 'tEA TIME SHOULD BE CHERISHED'