简体   繁体   English

我该如何处理JavaScript中较大的字符串?

[英]How can I deal with a reaaally large string in Javascript?

I'm writing a program to search 10 million digits of pi for a specific number. 我正在编写一个程序,以搜索pi的一千万个数字的特定数字。 I know there are programs out there to generate pi, but I'd rather search pregenerated pi digits for the number I need. 我知道那里有生成pi的程序,但是我宁愿在预生成的pi数字中搜索所需的数字。 I'm using CodePen, and although I've successfully copy pasted 10 million digits into the editor, it makes things really slow and clunky. 我使用的是CodePen,尽管我已经成功地将粘贴的1000万个数字复制到了编辑器中,但它确实使过程变得缓慢而笨拙。 Is there a way I can refer to the 10 million digits without actually copy pasting them? 有没有办法我可以引用1000万个数字而不实际复制粘贴它们?

var letters = [' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
$('#letters-and-numbers-wrapper').hide()
for (var i = 0; i <= 10; i++) {
  $('#background').append('<p class="background">x</p>')
}
// eventually make this whenever a letter is typed in the box
$('#search').keyup(function(){
  var query = $('#search').val()
query = query.toLowerCase();
  $('#rowTop').empty()
  $('#rowBottom').empty()
  $('#pi-img-wrapper').slideUp("slow").delay(1000)
   $('#letters-and-numbers-wrapper').slideDown("slow")
  for (var x = 0; x < query.length; x++) {
    $('#rowTop').append('<td class="top sequence">' + query[x] + '</td>')
    num = letters.indexOf(query[x])
    $('#rowBottom').append('<td class="bottom sequence">' + num + '</td>')
  }
});
var searchPi = function(numbers) {

}

http://codepen.io/Random_Pseudonym/pen/EWvdge http://codepen.io/Random_Pseudonym/pen/EWvdge

Thanks for any help! 谢谢你的帮助!

In codePen you can create another pen and then reference the URL to it using JS and load it as JSON into another pen. 在codePen中,您可以创建另一支笔,然后使用JS引用它的URL并将其作为JSON加载到另一支笔中。 Example here where I am loading in 104,000 digits of PI codepen.io/creativekinetix/pen/RpjjJK 我在这里以104,000位PI代码加载的示例pen.io/creativekinetix/pen/RpjjJK

Also, as maxwell suggested, though codePen won't allow the streaming, you could split the files up into chunks so you aren't loading all the digits at once. 而且,如maxwell所建议的那样,尽管codePen不允许流式传输,但是您可以将文件拆分为多个块,这样就不会一次加载所有数字。 Play around with that to see how performance is effected. 尝试一下,看看如何影响性能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM