码迷,mamicode.com
首页 > 其他好文 > 详细

[ Perl 6 ] 字符串基础操作

时间:2017-09-06 10:02:12      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:size   order   jid   字符串翻转   jmx   位置   https   mil   翻转   

 

[ Perl 6 ] 字符串基础操作

There is more than one way to do it.

  1. 字符串转换为列表:"banana".comb; # => (b a n a n a)
  2. 字符串长度:chars "banana"; "banana".chars; # => 6
  3. 字符串查找:
    • index "banana", "na"; # => 2
    • index "banana", "ni"; # => Nil
    • index "banana", "na", 3; # => 4
    • index "banana", "na", 5; # => Nil
    • rindex "banana", "na"; # => 4
    • rindex "banana", "na", 3; # => 2
  4. 字符串子串(起始位置、子串):
    • substr "I have a dream", 0, 6; # => I have
    • "I have a dream".substr(9, 5); # => dream
    • substr "I have a dream", 9, 10; # => dream
    • substr "I have a dream", *-5; # => dream
  5. 字符串翻转:flip "banana"; # => ananab
  6. 字符串分割(split):split "-", "2017-09-06"; # => (2017 09 06)
  7. 字符串连接:"ba" ~ "na"; # => bana
  8. 字符串合并(join):join "-", <I have a dream>; #=> I-have-a-dream
  9. 字符串大小写改变:
    • lc "April"; # => "april"
    • uc "april"; # => "APRIL"
    • tc "april"; # => "April"
?

[ Perl 6 ] 字符串基础操作

标签:size   order   jid   字符串翻转   jmx   位置   https   mil   翻转   

原文地址:http://www.cnblogs.com/wander4096/p/7482740.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!