# Error: symbol string may not contain \`\\0'

**URL:** <https://www.ruby-forum.com/t/error-symbol-string-may-not-contain-0/179230>\
**Category:** Ruby\
**Created:** [November 20, 2009, 5:24am UTC](https://www.ruby-forum.com/t/error-symbol-string-may-not-contain-0/179230 "2009-11-20T05:24:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![revenantphoenix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8edcca/32.png) [@revenantphoenix](https://www.ruby-forum.com/u/revenantphoenix)\
**Post date:** [November 20, 2009, 5:24am UTC](https://www.ruby-forum.com/t/error-symbol-string-may-not-contain-0/179230/1 "2009-11-20T05:24:41Z")

</div>

Basically it’s pretty self explanatory. I’m packing the following:

[0x00, 0x07, str1, str2, 0x00].pack(cA64A64c)

this is in fact, the exact way I need this packed. I understand how C  
strings work and such, but this really isn’t a C string, and it should  
pack just fine.

I move from C to Ruby and all I have are problems… I was just fine  
doing this with sprintf.

---

<div class="post-metadata">

**Author:** ![revenantphoenix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8edcca/32.png) [@revenantphoenix](https://www.ruby-forum.com/u/revenantphoenix)\
**Post date:** [November 20, 2009, 10:20am UTC](https://www.ruby-forum.com/t/error-symbol-string-may-not-contain-0/179230/2 "2009-11-20T10:20:28Z")

</div>

Dylan Lukes wrote:

> Basically it’s pretty self explanatory. I’m packing the following:
> 
> [0x00, 0x07, str1, str2, 0x00].pack(cA64A64c)

Please show the _exact_ code you are running, and the _exact_ error you  
are getting (use copy-paste for both), because what you have posted  
doesn’t make any sense and I cannot replicate the particular error you  
claim to see.

> > [0x00, 0x07, str1, str2, 0x00].pack(cA64A64c)  
> > NameError: undefined local variable or method `str1' for main:Object from (irb):1 str1 = "abc"; str2 = "def" => "def" [0x00, 0x07, str1, str2, 0x00].pack(cA64A64c) NameError: undefined local variable or method `cA64A64c’ for main:Object  
> > from (irb):3  
> > from :0  
> > [0x00, 0x07, str1, str2, 0x00].pack(“cA64A64c”)  
> > TypeError: can’t convert Fixnum into String  
> > from (irb):4:in `pack’  
> > from (irb):4  
> > from :0  
> > [0x00, 0x07, str1, str2, 0x00].pack(“ccA64A64c”)  
> > =\> “\000\aabc  
> > def \000”  
> > [0x00, 0x07, str1, str2, 0x00].pack(“ccA64A64c”)  
> > =\> “\000\aabc\000  
> > def \000”

After removing the obvious bugs from your code it looks fine to me, so  
if this doesn’t do what you want, you’ll have to explain what it is you  
are trying to do.

---

<div class="post-metadata">

**Author:** ![revenantphoenix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8edcca/32.png) [@revenantphoenix](https://www.ruby-forum.com/u/revenantphoenix)\
**Post date:** [November 20, 2009, 4:10pm UTC](https://www.ruby-forum.com/t/error-symbol-string-may-not-contain-0/179230/3 "2009-11-20T16:10:19Z")

</div>

I resolved it.

---

<div class="post-metadata">

**Author:** ![revenantphoenix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8edcca/32.png) [@revenantphoenix](https://www.ruby-forum.com/u/revenantphoenix)\
**Post date:** [November 20, 2009, 4:28pm UTC](https://www.ruby-forum.com/t/error-symbol-string-may-not-contain-0/179230/4 "2009-11-20T16:28:00Z")

</div>

Hi,

In message “Re: Error: symbol string may not contain `\0’”  
on Sat, 21 Nov 2009 00:10:21 +0900, Dylan Lukes  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

|I resolved it.

Could you tell me how?

```
          matz.

```
