SORU
24 EKİM 2010, Pazar


Nasıl dize dize geçtiği saymak için?

Kaç kez sayısını ben belirli bir dizenin başka bir dize içinde oluşur. Örneğin, bu Javascript ile yapmaya çalışıyorum

var temp = "This is a string.";
alert(temp.count("is")); //should output '2'

CEVAP
24 EKİM 2010, Pazar


var temp = "This is a string.";

// the g in the regular expression says to search the whole string 
// rather than just find the first occurrence
var count = (temp.match(/is/g) || []).length;

alert(count);

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • ChannelRichard

    ChannelRicha

    7 Kasım 2008
  • Lamarr Wilson

    Lamarr Wilso

    27 Aralık 2008
  • The Scary Snowman

    The Scary Sn

    1 ŞUBAT 2011