How to break the strings

How do you split a string into chars?

for example

the_string="newibe"

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

collect()

1 Like

See also: How to split all chars from string array - #4 by stevengj — 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.

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 :slight_smile:

Using loops is the Julian way. If you want good performance, don’t split the string, and use a loop.

4 Likes

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).

5 Likes