Article View: pl.comp.lang.javascript
Article #49848Re: newbie: łatwe: zliczanie wystąpień znaku w stringu
From: Paweł Arciszewski
Date: Thu, 25 Feb 2010 11:35
Date: Thu, 25 Feb 2010 11:35
22 lines
1876 bytes
1876 bytes
On 25 Lut, 12:12, jivanmuktaWYTNI...@poczta.onet.pl wrote:
> Ucz si JS i mam taki problem:
> jak najpro ciej zliczy w stringu wszystkie wyst pienia znaku "\n"? Czy da si
> bez pisania p tle? Nie mog znale odpowiedniej funkcji.
>
> --
> Wys ano z serwisu OnetNiusy:http://niusy.onet.pl
bez pętli chyba nie da rady ale jest łatwe:
function countNewLines(str){
var count = 0;
var lastIndex = 0;
while ((lastIndex = str.indexOf('\n', lastIndex)) != -1){
lastIndex ++;
count ++;
}
return count;
}
Pozdrawiam,
Paweł Arciszewski
Technical Details
Message-ID:
<4a09066e-a0e6-48f1-b014-9b4fec92bbf7@f8g2000yqn.googlegroups.com>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!newsfeed.pionier.net.pl!news.glorb.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!f8g2000yqn.googlegroups.com!not-for-mailReferences:
<4c17.0000009b.4b865b2c@newsgate.onet.pl>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!newsfeed.pionier.net.pl!news.glorb.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!f8g2000yqn.googlegroups.com!not-for-mail From: Paweł Arciszewski <p.arciszewski@archol.pl> Newsgroups: pl.comp.lang.javascript Subject: Re: newbie: łatwe: zliczanie wystąpień znaku w stringu Date: Thu, 25 Feb 2010 03:35:28 -0800 (PST) Organization: http://groups.google.com Lines: 23 Message-ID: <4a09066e-a0e6-48f1-b014-9b4fec92bbf7@f8g2000yqn.googlegroups.com> References: <4c17.0000009b.4b865b2c@newsgate.onet.pl> NNTP-Posting-Host: 87.205.218.120 Mime-Version: 1.0 X-Trace: posting.google.com 1267097728 2451 127.0.0.1 (25 Feb 2010 11:35:28 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 25 Feb 2010 11:35:28 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: f8g2000yqn.googlegroups.com; posting-host=87.205.218.120; posting-account=vizWWAoAAACs_i1DHpPX37yzHaehnrsM User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.0; pl; rv:1.9.1.8) Gecko/20100202 Firefox/3.5.8 (.NET CLR 3.5.30729),gzip(gfe),gzip(gfe) Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit