美文网首页
无标题文章

无标题文章

作者: 吸血鬼日记 | 来源:发表于2016-06-01 19:44 被阅读25次

str.match(pattern)

如果 pattern 不是正则表达是,则把 pattern 转换为正则表达式 Regexp,然后在 str 上调用它的匹配方法。

str.oct

把 str 的前导字符当作十进制数字的字符串(一个可选的符号),并返回相对应的数字。如果转换失败,则返回 0。

str.replace(other_str)

把 str 中的内容替换为 other_str 中的相对应的值。

str.reverse

返回一个新字符串,新字符串是 str 的倒序。

str.reverse!

逆转 str,str 会发生变化并返回。

str.rindex(substring [, fixnum]) [or]

str.rindex(fixnum [, fixnum]) [or]

str.rindex(regexp [, fixnum])

返回给定子字符串、字符(fixnum)或模式(regexp)在 str 中最后一次出现的索引。如果未找到则返回 nil。如果提供了第二个参数,则指定在字符串中结束搜索的位置。超出该点的字符将不被考虑。

str.rjust(integer, padstr=' ')

如果 integer 大于 str 的长度,则返回长度为 integer 的新字符串,新字符串以 str 右对齐,并以 padstr 作为填充。否则,返回 str。

str.rstrip

返回 str 的副本,移除了尾随的空格。

str.rstrip!

从 str 中移除尾随的空格,如果没有变化则返回 nil。

str.scan(pattern) [or]

str.scan(pattern) { |match, ...| block }

两种形式匹配 pattern(可以是一个正则表达式 Regexp 或一个字符串 String)遍历 str。针对每个匹配,会生成一个结果,结果会添加到结果数组中或传递给 block。如果 pattern 不包含分组,则每个独立的结果由匹配的字符串、$& 组成。如果 pattern 包含分组,每个独立的结果是一个包含每个分组入口的数组。

str.slice(fixnum) [or] str.slice(fixnum, fixnum) [or]

str.slice(range) [or] str.slice(regexp) [or]

str.slice(regexp, fixnum) [or] str.slice(other_str)

See str[fixnum], etc.

str.slice!(fixnum) [or] str.slice!(fixnum, fixnum) [or] str.slice!(range) [or] str.slice!(regexp) [or] str.slice!(other_str)

从 str 中删除指定的部分,并返回删除的部分。如果值超出范围,参数带有 Fixnum 的形式,将生成一个 IndexError。参数为 range 的形式,将生成一个 RangeError,参数为 Regexp 和 String 的形式,将忽略执行动作。

str.split(pattern=$;, [limit])

基于分隔符,把 str 分成子字符串,并返回这些子字符串的数组。

如果pattern是一个字符串 String,那么在分割 str 时,它将作为分隔符使用。如果 pattern 是一个单一的空格,那么 str 是基于空格进行分割,会忽略前导空格和连续空格字符。

如果pattern是一个正则表达式 Regexp,则 str 在 pattern 匹配的地方被分割。当 pattern 匹配一个玲长度的字符串时,str 被分割成单个字符。

如果省略了pattern参数,则使用 $; 的值。如果 $; 为 nil(默认的),str 基于空格进行分割,就像是指定了 ` ` 作为分隔符一样。

如果省略了limit参数,会抑制尾随的 null 字段。如果 limit 是一个正数,则最多返回该数量的字段(如果 limit 为 1,则返回整个字符串作为数组中的唯一入口)。如果 limit 是一个负数,则返回的字段数量不限制,且不抑制尾随的 null 字段。

相关文章

  • 无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标

    无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章 无标题文章无标题文章无标题文章无...

  • 无标题文章

    无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章

  • 无标题文章

    无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标...

  • 无标题文章

    无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标...

  • fasfsdfdf

    无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标...

  • 无标题文章

    无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标...

  • 无标题文章

    无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标...

  • 无标题文章

    无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标...

  • 无标题文章

    无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章

  • 无标题文章

    无标题文章 无标题文章 无标题文章无标题文章 无标题文章 无标题文章

网友评论

      本文标题:无标题文章

      本文链接:https://www.haomeiwen.com/subject/wvjxrttx.html