我想从一个非常大的字符串的开头剪切一些字符.为了节省一些内存和时间,我想避免复制它,但只是让字符串从后面的索引开始,就像在C中通过递增指向字符串(数组)的指针一样容易实现.
那可能吗?
你不能玩"增加字符串指针"的技巧,但试试这个:
str = 'I would like to cut a number of characters from the beginning of a very large String'
str[0, 10] = ''
str # => "ke to cut a number of characters from the beginning of a very large String"
Run Code Online (Sandbox Code Playgroud)
这是我知道在Ruby中删除部分字符串的最简单方法.
| 归档时间: |
|
| 查看次数: |
298 次 |
| 最近记录: |