Ruby 将每个单词的第一个字母追加到末尾
对于每个单词,我都试图将单词的第一个字母移动到单词的末尾。比如说,Ruby 将每个单词的第一个字母追加到末尾,ruby,Ruby,对于每个单词,我都试图将单词的第一个字母移动到单词的末尾。比如说, x = "hello" x << x.split("").shift # => "elloh" “这是一个示例”——>“hist si na-example” 我用一个词就做到了,比如 x = "hello" x << x.split("").shift # => "elloh" x=“你好” x“哦” 参考资料: “这是最好的时代,也是最糟糕的时代”。 gsub(/[\p{A
x = "hello"
x << x.split("").shift # => "elloh"
——>“这是一个示例”
“hist si na-example”
x = "hello"
x << x.split("").shift # => "elloh"
x=“你好”
x“哦”
参考资料:
“这是最好的时代,也是最糟糕的时代”。
gsub(/[\p{Alpha}']+/{s|s[1..-1]您的代码返回“helloh”
,而不是“elloh”
。“o'clock”会变成“clocko”吗?
"this is an example".gsub(/(\S)(\S+)/, '\2\1')
# => "hist si na xamplee"
"It was the best of times, it was the worst of times".
gsub(/[\p{Alpha}']+/) { |s| s[1..-1]<<s[0]}
#=> "tI asw het estb fo imest, ti asw het orstw fo imest"