# Write - accented characters take extra byte

**URL:** https://discourse.julialang.org/t/write-accented-characters-take-extra-byte/71271
**Category:** Internals & Design
**Tags:** strings
**Created:** [November 10, 2021, 5:49pm UTC](https://discourse.julialang.org/t/write-accented-characters-take-extra-byte/71271 "2021-11-10T17:49:14Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![yoh-meyers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yoh-meyers/32/14700_2.png) [@yoh-meyers](https://discourse.julialang.org/u/yoh-meyers)
#### Post date: [November 10, 2021, 5:49pm UTC](https://discourse.julialang.org/t/write-accented-characters-take-extra-byte/71271/1 "2021-11-10T17:49:14Z")

</div>

Hello,

When calling `write` with a string containing accented characters, I realise that 2 bytes are returned.

E.g:

```julia
julia> write(stdout, "ñ")
ñ2

julia> write(stdout, "n")
n1

```

This is an issue when the output is expecting a given length, for example HTTP parsing, relying on Sockets.

How can this be overcome?

Checking Julia code base, I see that `ccall` with chars is being used.

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [November 10, 2021, 5:50pm UTC](https://discourse.julialang.org/t/write-accented-characters-take-extra-byte/71271/2 "2021-11-10T17:50:17Z")

</div>

This is just standard UTF8. Not all characters are one byte.

---

<div class="post-metadata">

### Author: ![yoh-meyers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yoh-meyers/32/14700_2.png) [@yoh-meyers](https://discourse.julialang.org/u/yoh-meyers)
#### Post date: [November 10, 2021, 5:53pm UTC](https://discourse.julialang.org/t/write-accented-characters-take-extra-byte/71271/3 "2021-11-10T17:53:48Z")

</div>

Ah yes, makes sense indeed!

---

<div class="post-metadata">

### Author: ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)
#### Post date: [November 10, 2021, 6:10pm UTC](https://discourse.julialang.org/t/write-accented-characters-take-extra-byte/71271/4 "2021-11-10T18:10:16Z")

</div>

You can use `sizeof` to ask for the number of bytes required to write the string. `length` returns the number of characters.

---

<div class="post-metadata">

### Author: ![yoh-meyers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yoh-meyers/32/14700_2.png) [@yoh-meyers](https://discourse.julialang.org/u/yoh-meyers)
#### Post date: [November 10, 2021, 6:22pm UTC](https://discourse.julialang.org/t/write-accented-characters-take-extra-byte/71271/5 "2021-11-10T18:22:35Z")

</div>

Ah perfect, I was using `transcode(UInt8, string)`.  
No unnecessary conversion, with your suggestion!

---

<div class="post-metadata">

### Author: ![ptoche](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ptoche/32/23554_2.png) [@ptoche](https://discourse.julialang.org/u/ptoche)
#### Post date: [November 10, 2021, 6:36pm UTC](https://discourse.julialang.org/t/write-accented-characters-take-extra-byte/71271/6 "2021-11-10T18:36:51Z")

</div>

Many years ago my phone company charged per sms, where each sms had a fixed size. I discovered that while my phone indicated the number of characters used, the phone company charged by “byte”. I was careful not to omit accents then and typically maxed the allowed limit as indicated by my phone. As a result I exceeded the number of allowed bytes and ended up being charged for 2 sms for every one I had sent. Those were international rates too. Ah the naughties. 😢

---

<div class="post-metadata">

### Author: ![amrods](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amrods/32/2543_2.png) [@amrods](https://discourse.julialang.org/u/amrods)
#### Post date: [November 11, 2021, 10:31pm UTC](https://discourse.julialang.org/t/write-accented-characters-take-extra-byte/71271/7 "2021-11-11T22:31:47Z")

</div>

then “boomers” complained about kids writing “hru” and similar atrocities, haha
