Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a space between characters in a String [duplicate]

Possible Duplicate:
String Manipulation - Javascript -

I have a string:

hello 

and I want to add a space between each character to give:

h e l l o 

What is the best way to do this?

like image 574
freshest Avatar asked Sep 15 '11 20:09

freshest


People also ask

How do you put a space between characters in a string?

To add a space between the characters of a string, call the split() method on the string to get an array of characters, and call the join() method on the array to join the substrings with a space separator, e.g. str. split('').

How do you add a space in a string variable?

Use comma or just add space between them print("?" , d) print(e , '! ') OR print("?" +" "+ d) print(e +" "+'! ')

How do you give a space between characters in Java?

You can use the regular expression '..' to match each two characters and replace it with "$0 " to add the space: s = s. replaceAll("..", "$0 ");


2 Answers

"hello".split('').join(' '); // "h e l l o" 
like image 116
davin Avatar answered Sep 23 '22 00:09

davin


var text = "hello"; var betweenChars = ' '; // a space  alert(text.split('').join(betweenChars)); 
like image 38
Mike Edwards Avatar answered Sep 23 '22 00:09

Mike Edwards