# Why length(str) != sizeof(str)?

**URL:** <https://discourse.julialang.org/t/why-length-str-sizeof-str/36068>\
**Category:** General Usage\
**Created:** [March 16, 2020, 10:29pm UTC](https://discourse.julialang.org/t/why-length-str-sizeof-str/36068 "2020-03-16T22:29:57Z")\
**Posts on this page:** 2\
**Page:** 2

<div class="post-metadata">

**Author:** ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Post date:** [March 17, 2020, 1:37pm UTC](https://discourse.julialang.org/t/why-length-str-sizeof-str/36068/21 "2020-03-17T13:37:07Z")

</div>

> [@stevengj](#):
>
> > [@heliosdrm](#):
> >
> > In general, do not use `str[i]` unless you are sure `str` is made only of ASCII characters.
> 
> `str[i]` is perfectly fine for all strings, but you should only use an `i` that is returned by a function that produces valid indices.

In the wider context of the message, that sentence had the implicit meaning of: “do not use `str[i]` _to get the `i`-th character of `str`_ (…)”. I thought it was clear, but nevertheless, I have edited the previous post to make it explicit.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [March 17, 2020, 1:37pm UTC](https://discourse.julialang.org/t/why-length-str-sizeof-str/36068/22 "2020-03-17T13:37:27Z")

</div>

> [@pixel27](#):
>
> if you are displaying it…

If you are displaying it you might want `textwidth`

[Previous page](https://discourse.julialang.org/t/why-length-str-sizeof-str/36068.md?page=1)
