On Fri, Mar 21, 2014 at 12:12 PM, J Luis <[email protected]> wrote:

> I too want acknowledge all your work to explain why things work the way
> they do. But I want also say that I did read the docs before asking. It
> just happened that I missed that first part on the "Strings" that talk
> about strings immutability and error message does not help much leading us
> to the relevant manual section (I didn't go down the 'bytestrings', 'ascii'
> functions I missed the 'replace' one). Furthermore, this really should be
> mentioned to in the "Noteworthy differences from MATLAB" section as I'm
> sure others (Matlabers) will fall in the same hole.
>

Yes, the documentation is a bit spare. Sorry about that. It definitely
needs some work.

>
>
>> Getting back to your original example, I would counter that you never
>> really want to just do something like "replace the 16th character of this
>> string" in isolation. How did you figure out the index 16? What you really
>> want to do here is replace every instance of the NUL byte with a space. The
>> replace function will do that for you:
>>
>
> Yes, I wanted to remove the '\0' that I happened to know where it was
> because the first part of the string (obtained by concatenation) came from
> a ccall that gives back a Cstring (I actually solved the problem by not
> writing the last char of string one at the concatenation step)
>

Right. The trailing NUL byte is not generally considered to be part of a C
string – only the bytes before that are.

BTW, why doesn't the @sprint remove the NUL byte when we do
>
> julia> s1 = "ABC\0"
> "ABC\0"
>
> julia> @sprintf("%s Bla bla",s1)
> "ABC\0 Bla bla"
>

Because unlike C strings, Julia strings aren't NUL-terminated – they can
contain the '\0' character just fine. When they do, it is treated just like
any other character.

Reply via email to