gpt4 book ai didi

javascript - 在字符串末尾添加 X 行,从开头删除相同数量的行

转载 作者:可可西里 更新时间:2023-11-01 13:26:51 24 4
gpt4 key购买 nike

<分区>

我有一个大字符串显示在文本区域中。使用\n 将字符串分隔成行。程序运行时,新行会不断附加到字符串中。

为了防止程序速度变慢或浏览器崩溃,我不想显示超过 10k 行的文本。为此,我想从字符串的开头删除我添加到末尾的许多行。我该怎么做?

例如:

line 1
line 2
line 3
line 4
line 5
...
line 9,999
line 10,000

然后用 3 行新数据更新字符串

line 4
line 5
...
line 9,999
line 10,000
line 10,001
line 10,002
line 10,003

只是为了澄清,我没有将字符串从开头移动到结尾。我在末尾添加了完全不同的行,并从开头删除了相同数量的行。

我目前有这个:

function(addedText){
//prevent updating/refresh textarea with blank strings
if(addedText.length !== 0){}
//"#log-data" is an HTML textarea that displays all the text
//that is appended to it each time this function runs

x = number of lines in addedText

//Add addedText to the textarea
$("#log-data").append(addedText);

REMOVE x lines from start of "#log-data"
});

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