如何裁剪字符串而不复制它

rau*_*sch 1 ruby

我想从一个非常大的字符串的开头剪切一些字符.为了节省一些内存和时间,我想避免复制它,但只是让字符串从后面的索引开始,就像在C中通过递增指向字符串(数组)的指针一样容易实现.

那可能吗?

the*_*Man 5

你不能玩"增加字符串指针"的技巧,但试试这个:

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中删除部分字符串的最简单方法.