Insert commas between adjacent lower and upper case chars

Hi,

My coding skillz are a bit rusty these days and JavaScript was not one of my languages.

I am looking to insert a comma in a string whenever a lower case letter is followed by an upper case letter

e.g.

Convert

‘AaaBbbCcc’

into

‘Aaa,Bbb,Ccc’

I guess I need to loop through the string checking for lower followed by upper

What is the basic string loop syntax and is there an isUpper isLower function you can call on a char variable extracted from a string

something like:-

if(myString[3].isLower and myString[4].isUpper) then myString.insert(3,",")

Thanks

you can check whether string is lower or upper like so:

if (str[i] === str[i].toLowerCase())
OR
if (str[i] === str[i].toUpperCase())
of course you will need to loop through this, you can start by turning the string into an array for easier work.

function strings (str){
  str = str.split('')
for  (let i = 0; i < str.length; i++){
//Do stuff
}

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.