how to toUpperCase ignoring spaces? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

how to toUpperCase ignoring spaces?

need to tell the JS,to change every even string(counting from 0) to upperCase...(i have done it).but now i need to tell JS to ignore all spaces (' ')....every time string[i] === ' ' ;=> for loop restart his count from 0.. https://code.sololearn.com/WQSj4XN20912/?ref=app

3rd Mar 2020, 10:19 AM
Григорий Бондарев
Григорий Бондарев - avatar
10 Answers
3rd Mar 2020, 10:57 AM
Maninder $ingh
Maninder $ingh - avatar
+ 2
Григорий Бондарев hi, Have you considered first using split method on the string. It will convert your string into an array of strings. string=string.split(" "); Then if you need it to be a string type, you can use join() to get rid of the "," . and finally apply your for loop to get all the even indexed caracters passed to uppercase.
3rd Mar 2020, 3:04 PM
EmmanueLZ.
EmmanueLZ. - avatar
+ 1
Григорий Бондарев check my code again. now the output is that what you want. Just replacing the value of x 0 to -1.it's easy check it again.
4th Mar 2020, 2:28 AM
Maninder $ingh
Maninder $ingh - avatar
+ 1
77rtoip ,maybe but after I read again his question I realized he wanted to ignore them,not remove them,maybe he needs to keep the original form of the string,if so I guess your solution and the Maninder $ingh one are more appropriate.At least he have choice.
4th Mar 2020, 10:32 PM
EmmanueLZ.
EmmanueLZ. - avatar
0
Maninder $ingh almost... i need to make every even string for every word to upperCase (counting from 0 for each word). 0-th string must be upper,then 2-nd,then 4th.... in your code it 1st upper,then 3rd,then 5th....
3rd Mar 2020, 12:40 PM
Григорий Бондарев
Григорий Бондарев - avatar
3rd Mar 2020, 8:20 PM
77rtoip
3rd Mar 2020, 11:26 PM
EmmanueLZ.
EmmanueLZ. - avatar
0
The solution with split function is better, if you consider that you can have more than one space between words.
4th Mar 2020, 9:43 PM
77rtoip
0
Anyway it's not so simple as it look at the first glance ;-)
5th Mar 2020, 5:37 PM
77rtoip
- 1
hello
4th Mar 2020, 1:32 PM
mohammad naser
mohammad naser - avatar