gpt4 book ai didi

javascript - 每行添加一个字符

转载 作者:行者123 更新时间:2023-12-05 01:46:38 25 4
gpt4 key购买 nike

我有这种格式的文本

 Man like dog.
Man like to drink.
Man is the king

我想添加一个字符 say ????到上面文本中的每一行,以便输出看起来像:

 ????Man like dog.
????Man like to drink.
????Man is the king

你能帮我怎么做吗?

最佳答案

您可以使用正则表达式 (.replace(/^/gm, '????')) 执行此操作:

> str = "Man like dog.\nMan like to drink\nMan is the king."
'Man like dog.\nMan like to drink\nMan is the king.'
> str = str.replace(/^/gm, '????')
'????Man like dog.\n????Man like to drink\n????Man is the king.'
> console.log(str)
????Man like dog.
????Man like to drink
????Man is the king.

关于javascript - 每行添加一个字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34797678/

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