Top > Ruby [2.2.2] > tr


String# tr

p "1234567890".tr("3","0")          # "1204567890"
p "1234567890".tr("1-5","0")        # "0000067890"
p "achaporutepiipo".tr("a-c","A-C") # "AChAporutepiipo"
p "achaporutepiipo".tr("a,p","A,P") # "AchAPorutePiiPo"
p "acha,porute,piipo".tr(",","-")   # "acha-porute-piipo"

sugやgsubと一緒に覚えたいとこですが、trの方が覚えやすいかな。



Copyright © 2015 AchaPorutePiipo All Rights Reserved.