# About Strings and reference of strings

**URL:** <https://www.ruby-forum.com/t/about-strings-and-reference-of-strings/81489>\
**Category:** Ruby\
**Created:** [January 9, 2007, 12:38pm UTC](https://www.ruby-forum.com/t/about-strings-and-reference-of-strings/81489 "2007-01-09T12:38:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zenzei](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/7bcc69/32.png) [@zenzei](https://www.ruby-forum.com/u/zenzei)\
**Post date:** [January 9, 2007, 12:38pm UTC](https://www.ruby-forum.com/t/about-strings-and-reference-of-strings/81489/1 "2007-01-09T12:38:15Z")

</div>

Hello,

while writing a simple syslog message parser, something struck me and  
now I  
would like to know :  
What happens internally if you make a new string from a range of another  
string ?

You have a new String object. But what happens to the internal data ? Is  
the  
char range copied to the new string object or is a reference created to  
the  
range in the old string ?

If the data is copied over, I propose to introduce a new RefString Class  
as  
a C extension that would typically be used by parsers and tokenizers.

Cheers,  
zimbatm

---

<div class="post-metadata">

**Author:** ![zenzei](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/7bcc69/32.png) [@zenzei](https://www.ruby-forum.com/u/zenzei)\
**Post date:** [January 9, 2007, 12:49pm UTC](https://www.ruby-forum.com/t/about-strings-and-reference-of-strings/81489/2 "2007-01-09T12:49:18Z")

</div>

On 1/9/07, Jonas P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> If the data is copied over, I propose to introduce a new RefString Class as  
> a C extension that would typically be used by parsers and tokenizers.
> 
> Cheers,  
> zimbatm

You can see for yourself in string.c 😉  
Arrays are shared, so I _suppose_ Strings are as well.
