我有一个名为name的字符串,我希望修剪一个句子中的单词之间的空格,并在逗号之后修剪空格.我可以在句子的开头和结尾使用trim()修剪额外的空格.
[我正在使用javascript来实现我的代码]
name = ' Barack Hussein Obama II is an American politician who served as the 44th President of the United States from January 20, 2009, to January 20, 2017.
Run Code Online (Sandbox Code Playgroud)
预期产出:
name = ' Barack Hussein Obama II is an American politician who served as the 44th President of the United States from January 20, 2009, to January 20, 2017.
Run Code Online (Sandbox Code Playgroud)