Open chenhuiYj opened 4 years ago
有乱码的字符串 'I? ?love? the?? ?great ? ? ???wall' 和 'I?love ??the ?great ??wall in ?beijing' 。需要讲字符串还原为正确的句子 "I Love the Great Wall"和 "I Love The Great Wall in Beijing"。
'I? ?love? the?? ?great ? ? ???wall'
'I?love ??the ?great ??wall in ?beijing'
"I Love the Great Wall"
"I Love The Great Wall in Beijing"
' '
?
解题思路:先找出哪些单词前面有 ? 进行首字母大写处理。再把多余的 '' 和 ? 清楚
''
let str='I? ?love? the?? ?great ? ? ???wall' str.replace(/\?+([a-z])/g,function($1,$2,$3){return ' '+$2.toUpperCase()}).replace(/[\s\?]+/g,' ')
str='I?love ??the ?great ??wall in ?beijing' str.replace(/\?+([a-z])/g,function($1,$2,$3){return ' '+$2.toUpperCase()}).replace(/[\s\?]+/g,' ')
有乱码的字符串
'I? ?love? the?? ?great ? ? ???wall'
和'I?love ??the ?great ??wall in ?beijing'
。需要讲字符串还原为正确的句子"I Love the Great Wall"
和"I Love The Great Wall in Beijing"
。' '
和?
?
则该单词首字母大写解题思路:先找出哪些单词前面有
?
进行首字母大写处理。再把多余的''
和?
清楚