Perl6, how to remove the last character in a string?
Perl6, how to remove the last character in a string?
In Perl6, how does one remove the last character from a string
My Perl6 notes on how to remove the last letter of a string: perl6 -e my xa b c d ; x chop x ; say x; a b c d perl6 -e my xa b c d ; x s ; say x; a b c d Note means to match at the end of the string
Heres a way you can do it with substr: perl6 -e my a : abcde; say a.substr0, -1 abcd
chop will take the last character off a string, however sometimes you want to remove the line terminator so you would rather use chomp: my s hello world, hello worldn, hello worldr, hello worldrn ; my ct 0 ; for s - str say run , ct ; my s1 str ; my s2 str ; say orig ,str, ; say chop ,s1.chop, ; say chomp ,s2.chomp, ;
Комментарии
Отправить комментарий