Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

练习题3:字符串乱码问题 #14

Open
chenhuiYj opened this issue Jun 17, 2020 · 0 comments
Open

练习题3:字符串乱码问题 #14

chenhuiYj opened this issue Jun 17, 2020 · 0 comments

Comments

@chenhuiYj
Copy link
Owner

有乱码的字符串 'I? ?love? the?? ?great ? ? ???wall''I?love ??the ?great ??wall in ?beijing' 。需要讲字符串还原为正确的句子 "I Love the Great Wall""I Love The Great Wall in Beijing"

  1. 乱码字符只有 ' '?
  2. 如果单词前面是 ? 则该单词首字母大写

解题思路:先找出哪些单词前面有 ? 进行首字母大写处理。再把多余的 ''? 清楚

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,' ')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant