Split a string into its individual characters
There is often a need to split a string into the individual characters that make up the string. One such instance is in computing checksums - including the (relatively) straightforward check-digit used to validate routing numbers in the U.S. banking system.
MS Excel
So, how do we split a string in Excel into its individual components? My instinctive reaction was to use the TEXTSPLIT function with the empty string as the delimiter. It failed. Apparently, we need to specify a non-empty delimiter.
The next choice was the good ole MID function. Combine it with the SEQUENCE function to get the result in a single row or column.
If the string is in cell B3, we get the individual characters in individual cells in a single row with
=MID(B3,SEQUENCE(,LEN(B3)),1)
By contrast, to get the individual characters in a single column, use
=MID(B3,SEQUENCE(LEN(B3)),1)
The next logical step is to create a lambda function that accepts a parameter for how it returns the characters - by row or by column.
=LAMBDA(_str,_byRow,
? ? LET(_byRowVal,IF(ISOMITTED(_byRow),FALSE,_byRow),
? ? ? ? MID(_str,
? ? ? ? ? ? SEQUENCE(IF(_byRowVal,LEN(_str),1),IF(_byRowVal,1,LEN(_str))),1)
? ? ))
Python
Three ways to split a string into its individual characters. As a building block for additional analysis, the last one is arguably the most useful
str='111000025'
print([*str])
print(list(str))
print([x for x in str])