I want to add a space between a lowercase and uppercase in one string. For example:
FruityLoops
FirstRepeat
Now I want to add a space between the lowercase and uppercase letters. I don't know how I should start in JavaScript. Something with substr or search? Can somebody can help me?
Use the replace() method to insert a space before the capital letters in a string, e.g. str. replace(/[A-Z]/g, ' $&'). trim() . The replace method will return a new string, where each capital letter is replaced by a space preceding the capital letter.
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('').
JavaScript provides two helpful functions for converting text to uppercase and lowercase. String. toLowerCase() converts a string to lowercase, and String. toUpperCase() converts a string to uppercase.
var str = "FruityLoops";
str = str.replace(/([a-z])([A-Z])/g, '$1 $2');
Example: http://jsfiddle.net/3LYA8/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With