indexof ()
Giriş dizesi içinde belirtilen bir dizginin ilk geçişinin sıfır tabanlı dizinini raporlar.
Arama ya da giriş dizgisi dizgi tipinde değilse, işlev zorla dizgideğerine dönüştürür.
Sözdizimi
indexof(kaynak,arama[,başlangı_dizini[,uzunluk[,geçiş]]])
Bağımsız değişkenler
- source: Giriş dizgisi.
- lookup: Aramak için dizgi.
- start_index: Arama başlangıç konumu. Negatif bir değer, başlangıç arama konumunu kaynağın sonundan şu kadar Ekbirçok olanağı 1 başlayamesinin gelmiş lerine göre gösterir: abs (start_index). İsteğe bağlı.
- length: İncelenecek karakter konumu sayısı. -1 değeri, sınırsız uzunluk anlamına gelir. İsteğe bağlı.
- geçiş: Oluşum sayısı. Varsayılan 1. İsteğe bağlı.
İadeler
Arama' nin sıfır tabanlı dizin konumu.
Girişte dizgi bulunamazsa -1 değerini döndürür.
İlgisiz girişler için (geçiş < 0 ya da uzunluk < -1)- boş değerdöndürür.
Örnekler
print
idx1 = indexof("abcdefg","cde") // lookup found in input string
, idx2 = indexof("abcdefg","cde",1,4) // lookup found in researched range
, idx3 = indexof("abcdefg","cde",1,2) // search starts from index 1, but stops after 2 chars, so full lookup can't be found
, idx4 = indexof("abcdefg","cde",3,4) // search starts after occurrence of lookup
, idx5 = indexof("abcdefg","cde",-5) // negative start index
, idx6 = indexof(1234567,5,1,4) // two first parameters were forcibly casted to strings "12345" and "5"
, idx7 = indexof("abcdefg","cde",2,-1) // lookup found in input string
, idx8 = indexof("abcdefgabcdefg", "cde", 1, 10, 2) // lookup found in input range
, idx9 = indexof("abcdefgabcdefg", "cde", 1, -1, 3) // the third occurrence of lookup is not in researched range
### Sonuçlar| idx1 | idx2 | idx3 | idx4 | idx5 | idx6 | idx7 | idx8 | idx9 |
|---|---|---|---|---|---|---|---|---|
| 2 | 2 | 2 | -1 | 2 | 4 | 2 | 9 | -1 |