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

من موسوعة حسوب
اذهب إلى التنقل اذهب إلى البحث
(أنشأ الصفحة ب'<noinclude>{{DISPLAYTITLE: التابع text.lastIndexOfAny()‎ في لغة Kotlin}}</noinclude> تعيد الدالة <code>lastIndexOfAny()‎</code> فهرس أول...')
 
سطر 1: سطر 1:
 
<noinclude>{{DISPLAYTITLE: التابع text.lastIndexOfAny()‎ في لغة Kotlin}}</noinclude>
 
<noinclude>{{DISPLAYTITLE: التابع text.lastIndexOfAny()‎ في لغة Kotlin}}</noinclude>
تعيد الدالة <code>lastIndexOfAny()‎</code> فهرس أول ظهور للحرف أو [[Kotlin/String|السلسلة النصية]] المُمرّرة إليها في [[Kotlin/CharSequence/index|سلسلة الحروف]] التي استُدعيت عبرها بداية من الفهرس المُمرّر <code>startIndex</code>، في حال كان ذلك الحرف أو تلك  [[Kotlin/String|السلسلة النصية]] المُمرّرة غير موجودة فستعيد الدالةُ العدد ‎<code>-1</code>.
+
تعيد الدالة <code>lastIndexOfAny()‎</code> فهرس آخر ظهور لأيّ من الحروف أو [[Kotlin/String|السلاسل النصية]] الواردة في الوسيط المُمرّر (<code>chars</code> أو <code>strings</code>
  
في حال إعطاء الوسيط <code>ignoreCase</code>   القيمة <code>true</code>فإنّ الدالة <code>indexOf()‎</code> لن تفرق بين الحروف الكبيرة والصغيرة.
+
في حال إعطاء الوسيط <code>ignoreCase</code> القيمة <code>true</code> فإنّ الدالة <code>lastIndexOfAny()‎</code> لن تفرق بين الحروف الكبيرة والصغيرة.
 
==البنية العامة==
 
==البنية العامة==
 
<syntaxhighlight lang="kotlin">
 
<syntaxhighlight lang="kotlin">
fun CharSequence.indexOf(
+
fun CharSequence.lastIndexOfAny(
     char: Char,  
+
     chars: CharArray,  
     startIndex: Int = 0,  
+
     startIndex: Int = lastIndex,  
 
     ignoreCase: Boolean = false
 
     ignoreCase: Boolean = false
 
): Int
 
): Int
  
fun CharSequence.indexOf(
+
fun CharSequence.lastIndexOfAny(
     string: String,  
+
     strings: Collection<String>,  
     startIndex: Int = 0,  
+
     startIndex: Int = lastIndex,  
 
     ignoreCase: Boolean = false
 
     ignoreCase: Boolean = false
): Int  
+
): Int
 
</syntaxhighlight>
 
</syntaxhighlight>
 
==القيم المعادة==
 
==القيم المعادة==
سطر 21: سطر 21:
 
==أمثلة==
 
==أمثلة==
 
===استخدام  الدالة<code>()lastIndexOfAny</code>مع سلسلة نصية===
 
===استخدام  الدالة<code>()lastIndexOfAny</code>مع سلسلة نصية===
تعرف الشيفرة الآتية <nowiki/>[[Kotlin/String|سلسلة نصية]] باسم <code>str</code>، ثم تعرّف مصفوفة من النوع <code>CharArray</code> باسم <code>chars</code>، ثم تستدعي الدالة  <code>()lastIndexOfAny</code> عبر <code>str</code> للحصول على فهرس أول ظهور  لأي حرف من الحروف الموجودة في<code>CharArray</code> ، ثم تطبع الناتج:<syntaxhighlight lang="kotlin">
+
تعرف الشيفرة الآتية <nowiki/>[[Kotlin/String|سلسلة نصية]] باسم <code>str</code>، ثم تعرّف مصفوفة من النوع <code>CharArray</code> باسم <code>chars</code>، ثم تستدعي الدالة  <code>()lastIndexOfAny</code> عبر <code>str</code> للحصول على فهرس آخر ظهور  لأي حرف من الحروف الموجودة في<code>CharArray</code> ، ثم تطبع الناتج:<syntaxhighlight lang="kotlin">
 
fun main(args: Array<String>) {
 
fun main(args: Array<String>) {
 
var str = "hsoub"
 
var str = "hsoub"
 
var chars = charArrayOf('x', 'r', 'b')
 
var chars = charArrayOf('x', 'r', 'b')
 
      
 
      
print(str.indexOfAny(chars)) // 1
+
print(str.lastIndexOfAny(chars)) // 4
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 
===استخدام  الدالة<code>()lastIndexOfAny</code>مع سلسلة نصية: الحالة الثانية===
 
===استخدام  الدالة<code>()lastIndexOfAny</code>مع سلسلة نصية: الحالة الثانية===
تعرف الشيفرة الآتية <nowiki/>[[Kotlin/String|سلسلة نصية]] باسم <code>str</code>، ثم تعرّف مصفوفة من النوع <code>CharArray</code> باسم <code>chars</code>، ثم تستدعي الدالة  <code>()lastIndexOfAny</code> عبر <code>str</code> للحصول على فهرس أول ظهور  لأي حرف من الحروف الموجودة في<code>CharArray</code> ، ولما كانت كل حروف <code>CharArray</code> غير موجودة في <code>str</code> فستعيد العدد ‎<code>-1:</code><syntaxhighlight lang="kotlin">
+
تعرف الشيفرة الآتية <nowiki/>[[Kotlin/String|سلسلة نصية]] باسم <code>str</code>، ثم تعرّف مصفوفة من النوع <code>CharArray</code> باسم <code>chars</code>، ثم تستدعي الدالة  <code>()lastIndexOfAny</code> عبر <code>str</code> للحصول على فهرس آخر ظهور  لأي حرف من الحروف الموجودة في<code>CharArray</code> ، ولما كانت كل حروف <code>CharArray</code> غير موجودة في <code>str</code> فستعيد العدد ‎<code>-1:</code><syntaxhighlight lang="kotlin">
 
fun main(args: Array<String>) {
 
fun main(args: Array<String>) {
 
var str = "hsoub"
 
var str = "hsoub"
 
var chars = charArrayOf('x', 'r', 'w')
 
var chars = charArrayOf('x', 'r', 'w')
 
      
 
      
print(str.indexOfAny(chars)) // -1
+
print(str.lastIndexOfAny(chars)) // -1
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
سطر 41: سطر 41:
 
*<code>[[Kotlin/kotlin.text/indexOf|indexOf]]()‎</code>: تعيد الدالة <code>indexOf()‎</code> فهرس أول ظهور للحرف أو [[Kotlin/String|السلسلة النصية]] المُمرّرة إليها في [[Kotlin/CharSequence/index|سلسلة الحروف]] التي استُدعيت عبرها بداية من الفهرس المُمرّر <code>startIndex</code>، في حال كان ذلك الحرف غير موجود فستعيد العدد ‎<code>-1</code>. 
 
*<code>[[Kotlin/kotlin.text/indexOf|indexOf]]()‎</code>: تعيد الدالة <code>indexOf()‎</code> فهرس أول ظهور للحرف أو [[Kotlin/String|السلسلة النصية]] المُمرّرة إليها في [[Kotlin/CharSequence/index|سلسلة الحروف]] التي استُدعيت عبرها بداية من الفهرس المُمرّر <code>startIndex</code>، في حال كان ذلك الحرف غير موجود فستعيد العدد ‎<code>-1</code>. 
 
==مصادر==
 
==مصادر==
<span> </span>
 
 
*[http://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/index-of-any.html الدالة text.lastIndexOfAny()‎  في التوثيق الرسمي للمكتبة القياسية في لغة Kotlin.]
 
*[http://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/index-of-any.html الدالة text.lastIndexOfAny()‎  في التوثيق الرسمي للمكتبة القياسية في لغة Kotlin.]
 
[[تصنيف:Kotlin]]
 
[[تصنيف:Kotlin]]
 
[[تصنيف:Kotlin Methods]]
 
[[تصنيف:Kotlin Methods]]

مراجعة 09:55، 10 يوليو 2018

تعيد الدالة lastIndexOfAny()‎ فهرس آخر ظهور لأيّ من الحروف أو السلاسل النصية الواردة في الوسيط المُمرّر (chars أو strings

في حال إعطاء الوسيط ignoreCase القيمة true فإنّ الدالة lastIndexOfAny()‎ لن تفرق بين الحروف الكبيرة والصغيرة.

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

fun CharSequence.lastIndexOfAny(
    chars: CharArray, 
    startIndex: Int = lastIndex, 
    ignoreCase: Boolean = false
): Int

fun CharSequence.lastIndexOfAny(
    strings: Collection<String>, 
    startIndex: Int = lastIndex, 
    ignoreCase: Boolean = false
): Int

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

عدد.

أمثلة

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

تعرف الشيفرة الآتية سلسلة نصية باسم str، ثم تعرّف مصفوفة من النوع CharArray باسم chars، ثم تستدعي الدالة  ()lastIndexOfAny عبر str للحصول على فهرس آخر ظهور لأي حرف من الحروف الموجودة فيCharArray ، ثم تطبع الناتج:

fun main(args: Array<String>) {
var str = "hsoub"
var chars = charArrayOf('x', 'r', 'b')
    
print(str.lastIndexOfAny(chars)) // 4
}

استخدام الدالة()lastIndexOfAnyمع سلسلة نصية: الحالة الثانية

تعرف الشيفرة الآتية سلسلة نصية باسم str، ثم تعرّف مصفوفة من النوع CharArray باسم chars، ثم تستدعي الدالة  ()lastIndexOfAny عبر str للحصول على فهرس آخر ظهور لأي حرف من الحروف الموجودة فيCharArray ، ولما كانت كل حروف CharArray غير موجودة في str فستعيد العدد ‎-1:

fun main(args: Array<String>) {
var str = "hsoub"
var chars = charArrayOf('x', 'r', 'w')
    
print(str.lastIndexOfAny(chars)) // -1
}

انظر أيضًا

  • indexOf()‎: تعيد الدالة indexOf()‎ فهرس أول ظهور للحرف أو السلسلة النصية المُمرّرة إليها في سلسلة الحروف التي استُدعيت عبرها بداية من الفهرس المُمرّر startIndex، في حال كان ذلك الحرف غير موجود فستعيد العدد ‎-1

مصادر