Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Translate c using c1

Former Member
0 Kudos

Hi all,

What is the use of Translate c using c1 ststement ?

could you please explain wit a exapmle ?

thanks in advance

Krish...

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi

syntx : TRANSLATE src USING dest.

The TRANSLATE command groups the characters in dest string in pairs .

it then changes the characters in src string using the corresponding 2nd character

of the pair in the destination string.

Data : num(10) value '123456' ,

chars(10) value '1a2b3c4d5e6f0'.

Eq TRANSLATE num using chars.

The resulting value in num is 'abcdef' .

Explain . for 1 in num , the refernce is made to pairs in chars , here '1a' pair.

the first value in pair is replaced with the secondvalue ie 1 by a .

lly for 2 in num , reference to 2b in chars is made .. the matching 2 in num is replaced by the second entry in the pair in chars ie 'b' in the pair '2b' .

i hope this helps u.

regards

Pankaj

3 REPLIES 3

Former Member
0 Kudos

If you specify USING, the characters in text are converted according to the rule specified in pattern. pattern must be a character-type data object whose contents are interpreted as a sequence of character pairs. text is searched for the first character of each pair, starting with the first pair, and each location found is replaced with the second character of the pair. The search is case-sensitive. If pattern contains a character multiple times as the first character of a pair, only the first pair is taken into account. A character in text that has already been replaced cannot be replaced again in the same TRANSLATE statement. Therefore, if the second character of a pair in pattern appears as the first character of a subsequent pair, the second pair affects only the original characters in text.

Trailing blanks in data objects text and pattern are taken into account for data objects. If pattern contains an uneven number of characters, the last character is ignored. If pattern is a blank string, no replacements take place.

Example

Converts the characters "A" to "B", "a" to "b", and vice versa. text contains "Abracadabra" after the conversion.

DATA text TYPE string.

text = `Barbcbdbarb`.

Former Member
0 Kudos

Hi,

Read this, u will understand what translate does.

Translate abc using pattern.

If you specify USING, the characters in text are converted according to the rule specified in pattern. pattern must be a character-type data object whose contents are interpreted as a sequence of character pairs. text is searched for the first character of each pair, starting with the first pair, and each location found is replaced with the second character of the pair. The search is case-sensitive. If pattern contains a character multiple times as the first character of a pair, only the first pair is taken into account. A character in text that has already been replaced cannot be replaced again in the same TRANSLATE statement. Therefore, if the second character of a pair in pattern appears as the first character of a subsequent pair, the second pair affects only the original characters in text.

Trailing blanks in data objects text and pattern are taken into account for data objects. If pattern contains an uneven number of characters, the last character is ignored. If pattern is a blank string, no replacements take place.

Translate, in this case, will replace all occurances of a "-" with a space.

translate p_number using '- '.

Another example, say that you want do translate all commas, to periods. You could do this.

translate p_number using '-.'.

Regards,

Kumar

Former Member
0 Kudos

hi

syntx : TRANSLATE src USING dest.

The TRANSLATE command groups the characters in dest string in pairs .

it then changes the characters in src string using the corresponding 2nd character

of the pair in the destination string.

Data : num(10) value '123456' ,

chars(10) value '1a2b3c4d5e6f0'.

Eq TRANSLATE num using chars.

The resulting value in num is 'abcdef' .

Explain . for 1 in num , the refernce is made to pairs in chars , here '1a' pair.

the first value in pair is replaced with the secondvalue ie 1 by a .

lly for 2 in num , reference to 2b in chars is made .. the matching 2 in num is replaced by the second entry in the pair in chars ie 'b' in the pair '2b' .

i hope this helps u.

regards

Pankaj