taking x amount of words out of text file

archel

Client
Регистрация
02.05.2011
Сообщения
175
Благодарностей
22
Баллы
18
Hi

I would like to be able to take eg. the first 500 words out of a big text file and then delete that part.
Anyone knows an easy way to do that?

Only thing I could think of for now is pulling one word per word with regexp and then replace it with nothing...but that's a bit clumsy.
 

archel

Client
Регистрация
02.05.2011
Сообщения
175
Благодарностей
22
Баллы
18
Ok found it... if anyone would ever need it:

I take the original text and take the first x amounts of words, here the first 5::
var str1 = "This is my sentence that consists out of 10 words.";
var str2 = str1.replace(/(([^\s]+\s\s*){5})(.*)/,"$1");

Then I can use the output of str2 for whatever I want.


Later on I take the original text again and replace it with the rest (here the last 5 words):
var str1 = "This is my sentence that consists out of 10 words.";
var str3= str1.replace(/(([^\s]+\s\s*){5})(.*)/,"$3");

Then I save the output of str3 in textfile from which I pulled the original text from.
 
  • Спасибо
Реакции: gcomm

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)