# How to break the strings

**URL:** <https://discourse.julialang.org/t/how-to-break-the-strings/73602>\
**Category:** New to Julia\
**Tags:** strings, char\
**Created:** [December 25, 2021, 3:47am UTC](https://discourse.julialang.org/t/how-to-break-the-strings/73602 "2021-12-25T03:47:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![junux](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/junux/32/32219_2.png) [@junux](https://discourse.julialang.org/u/junux)\
**Post date:** [December 25, 2021, 3:47am UTC](https://discourse.julialang.org/t/how-to-break-the-strings/73602/1 "2021-12-25T03:47:15Z")

</div>

How do you split a string into chars?

for example

```julia
the_string="newibe"

result=('n', 'e', 'w', 'i', 'b', 'e')

```

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [December 25, 2021, 4:01am UTC](https://discourse.julialang.org/t/how-to-break-the-strings/73602/2 "2021-12-25T04:01:23Z")

</div>

`collect()`

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [December 25, 2021, 2:07pm UTC](https://discourse.julialang.org/t/how-to-break-the-strings/73602/3 "2021-12-25T14:07:46Z")

</div>

See also: [How to split all chars from string array - #4 by stevengj](https://discourse.julialang.org/t/how-to-split-all-chars-from-string-array/45965/4) — it’s relatively rare to need this, since you can get characters directly from a string by indexing/iterating, rather than `collect`-ing into a separate array first.

---

<div class="post-metadata">

**Author:** ![junux](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/junux/32/32219_2.png) [@junux](https://discourse.julialang.org/u/junux)\
**Post date:** [December 25, 2021, 2:25pm UTC](https://discourse.julialang.org/t/how-to-break-the-strings/73602/4 "2021-12-25T14:25:47Z")

</div>

You’re right  
However in my situation i thought it would be faster to collecting it then use the result, rather than using a for loop.

I’m trying to write in Julian way 🙂

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [December 25, 2021, 2:52pm UTC](https://discourse.julialang.org/t/how-to-break-the-strings/73602/5 "2021-12-25T14:52:00Z")

</div>

Using loops _is_ the Julian way. If you want good performance, _don’t_ split the string, and use a loop.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [December 25, 2021, 5:13pm UTC](https://discourse.julialang.org/t/how-to-break-the-strings/73602/6 "2021-12-25T17:13:03Z")

</div>

It does depend on the application. If you need O(1) linear indexing of characters then collect first would be faster at the expense of 4x memory (typically).
