الفرق بين المراجعتين ل"Kotlin/kotlin.text/withIndex"

من موسوعة حسوب
اذهب إلى التنقل اذهب إلى البحث
ط (استبدال النص - 'Kotlin Functions' ب'Kotlin Function')
سطر 33: سطر 33:
 
*[http://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/with-index.html الدالة text.withIndex()‎ في التوثيق الرسميّ للمكتبة القياسيّة في لغة Kotlin.]
 
*[http://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/with-index.html الدالة text.withIndex()‎ في التوثيق الرسميّ للمكتبة القياسيّة في لغة Kotlin.]
 
[[تصنيف:Kotlin]]
 
[[تصنيف:Kotlin]]
[[تصنيف:Kotlin Functions]]
+
[[تصنيف:Kotlin Function]]

مراجعة 11:35، 30 أغسطس 2018

تعيد الدالة withIndex()‎ مُكرّرا مؤجّلًا (lazy Iterable) مكونًا من عناصر من الصنف IndexedValue لكل حرف من حروف سلسلة الحروف التي استُدعيت عبرها.

البنية العامة

fun CharSequence.withIndex(): Iterable<IndexedValue<Char>>

القيم المعادة

مُكرّر مؤجّل (lazy Iterable) مكون من عناصر من الصنف IndexedValue

أمثلة

استخدام الدالة ()withIndex مع سلسلة نصية

تستدعي الشيفرة الآتية الدالة ()withIndex عبر سلسلة نصية وتحيل الناتج إلى المتغير iter، ثم تستخدمه في حلقة تكرارية for:

fun main(args: Array<String>) {
val iter = "hsoub".withIndex()
     
for (x in iter) println(x)    
// المخرجات
//IndexedValue(index=0, value=h)
//IndexedValue(index=1, value=s)
//IndexedValue(index=2, value=o)
//IndexedValue(index=3, value=u)
//IndexedValue(index=4, value=b)
}

انظر أيضًا

مصادر