I am trying to create a function that inserts spaces between the characters of a string argument then return a new string which contains the same characters as the argument, separated by space characters.
E.g.
Hello
becomes
H e l l o
I’m a massive novice and I’m sure that this might seem like a no-brain’er to some people, but I just can’t seem to get my head around it.
You can use the
split()function to turn the string into an array of single characters, and then thejoin()function to turn that back into a string where you specify a joining character (specifying space as the joining character):(Note that the parameter to
split()is the character you want to split on so, e.g., you can usesplit(",")to break up a comma-separated list, but if you pass an empty string it just splits up every character.)