gpt4 book ai didi

javascript - 如何删除段落中的多余行

转载 作者:行者123 更新时间:2023-11-28 05:07:13 24 4
gpt4 key购买 nike

我有从 api 调用的这条信息:

例如,

"

1. Assist food and technology department in record keeping and filing"

如何去掉多余的线?

最佳答案

只需删除字符串开头和结尾的所有空格即可。这就是.trim()是:

s = `

1. Assist food and technology department in record keeping and filing

`;
s = s.trim();
console.log(s);

trim() 的替代方案(如果您的浏览器不支持它?)是正则表达式:

s = '\n\n1. Assist food and technology department in record keeping and filing   \n \r\n   ';
s = s.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
console.log(s);

关于javascript - 如何删除段落中的多余行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41647927/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com