Splitting a string to all it's characters
Asked Answered
D

4

4

This should have been simple but I can't find a workaround. I want to split a string into its characters. e.g. dog will be sepearted to: d o g

The problem is I can't put an empty character as a delimiter in the SPLIT function. What am I missing?

Draught answered 23/4, 2021 at 11:7 Comment(1)
The following link includes some answers that might indicate how to do this: webapps.stackexchange.com/questions/51648/…Aribold
S
3

Something like this ?

=split(regexreplace(A2, "(.)", "$1_"), "_")

or if you'd want an arrayformula to process a column at once

=ArrayFormula(if(len(A2:A), split(regexreplace(A2:A, "(.)", "$1_"), "_"),))

enter image description here

enter image description here

Reference

More info on how this works? Check this link.

Stevens answered 23/4, 2021 at 11:14 Comment(5)
This is great, thanks. Can you please explain how this works?Draught
The regexreplace adds an underscore after every character (that's what the dot means in regular expression). Correcter: it replaces every character with the same character with an added underscore. Then, split is used (with the underscore as delimiter) to create the array of separate characters.Stevens
Also added some additional info in the answer.Stevens
Thanks, so (.) represents a character, and $1_ represents adding _ to the character? Why $1 and not (.)_ ? This looks more intuitiveDraught
Regular expressions have a specific syntax. To learn more about that syntax, check this link: support.google.com/a/answer/1371415?hl=enStevens
S
8

Also

=ArrayFormula(mid(A1,sequence(1,len(A1)),1))

enter image description here

Snowwhite answered 23/4, 2021 at 11:16 Comment(0)
S
3

Something like this ?

=split(regexreplace(A2, "(.)", "$1_"), "_")

or if you'd want an arrayformula to process a column at once

=ArrayFormula(if(len(A2:A), split(regexreplace(A2:A, "(.)", "$1_"), "_"),))

enter image description here

enter image description here

Reference

More info on how this works? Check this link.

Stevens answered 23/4, 2021 at 11:14 Comment(5)
This is great, thanks. Can you please explain how this works?Draught
The regexreplace adds an underscore after every character (that's what the dot means in regular expression). Correcter: it replaces every character with the same character with an added underscore. Then, split is used (with the underscore as delimiter) to create the array of separate characters.Stevens
Also added some additional info in the answer.Stevens
Thanks, so (.) represents a character, and $1_ represents adding _ to the character? Why $1 and not (.)_ ? This looks more intuitiveDraught
Regular expressions have a specific syntax. To learn more about that syntax, check this link: support.google.com/a/answer/1371415?hl=enStevens
A
1

Try the following

=SPLIT(REGEXREPLACE(O13,"(.)","$1"&"-"),"-",1,1)

enter image description here

Acetometer answered 23/4, 2021 at 11:14 Comment(0)
M
1

Here's another way to do this:

=SPLIT(REGEXREPLACE(A1,," ")," ")

enter image description here

The following formula inserts a space between each character:

=REGEXREPLACE(A1,," ")

enter image description here

Then we SPLIT by it.

Mathildamathilde answered 5/4, 2024 at 20:47 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.