tr(p1, p2)
public
Returns a copy of str with the characters in from_str
replaced by the corresponding characters in to_str. If to_str is shorter than
from_str, it is padded with its last character. Both strings may
use the c1—c2 notation to denote ranges of characters, and
from_str may start with a ^, which denotes all characters
except those listed.
"hello".tr('aeiou', '*')
"hello".tr('^aeiou', '*')
"hello".tr('el', 'ip')
"hello".tr('a-y', 'b-z')
Show source
/*
* call-seq:
* str.tr(from_str, to_str) => new_str
*
* Returns a copy of <i>str</i> with the characters in <i>from_str</i> replaced
* by the corresponding characters in <i>to_str</i>. If <i>to_str</i> is
* shorter than <i>from_str</i>, it is padded with its last character. Both
* strings may use the c1--c2 notation to denote ranges of characters, and
* <i>from_str</i> may start with a <code>^</code>, which denotes all
* characters except those listed.
*
* "hello".tr('aeiou', '*')
* "hello".tr('^aeiou', '*')
* "hello".tr('el', 'ip')
* "hello".tr('a-y', 'b-z')
*/
static VALUE
rb_str_tr(str, src, repl)
VALUE str, src, repl;
{
str = rb_str_dup(str);
tr_trans(str, src, repl, 0);
return str;
}