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

من موسوعة حسوب
اذهب إلى التنقل اذهب إلى البحث
(أنشأ الصفحة ب'<noinclude>{{DISPLAYTITLE: التابع text.toCollection()‎ في لغة Kotlin}}</noinclude> تعيد الدالة <code>toCollection()</code>‎ مصفوفة من ا...')
 
سطر 1: سطر 1:
 
<noinclude>{{DISPLAYTITLE: التابع text.toCollection()‎ في لغة Kotlin}}</noinclude>
 
<noinclude>{{DISPLAYTITLE: التابع text.toCollection()‎ في لغة Kotlin}}</noinclude>
تعيد الدالة <code>toCollection()</code>‎ مصفوفة من النوع <code>[[Kotlin/CharArray/index|CharArray]]</code> تحتوي حروف [[Kotlin/String|السلسلة النصية]] التي استٌدعيت عبرها.
+
تضيف الدالة <code>toCollection()</code>‎ كل حروف [[Kotlin/CharSequence/index|سلسلة الحروف]]  التي استٌدعيت عبرها إلى الوسيط المُمرّر <code>destination</code>.
  
 
== البنية العامة ==
 
== البنية العامة ==
 
<syntaxhighlight lang="kotlin">
 
<syntaxhighlight lang="kotlin">
inline fun String.toCharArray(): CharArray
+
fun <C : MutableCollection<in Char>> CharSequence.toCollection(
 
+
     destination: C
</syntaxhighlight>'''بيئة التشغيل المطلوبة: JVM'''
+
): C
 
+
</syntaxhighlight>
تعيد الدالة <code>toCharArray()</code>‎ مصفوفة من النوع <code>[[Kotlin/CharArray/index|CharArray]]</code> تحتوي حروف [[Kotlin/String|السلسلة النصية]] التي استٌدعيت عبرها.<syntaxhighlight lang="kotlin">
 
inline fun String.toCharArray(
 
     destination: CharArray,
 
    destinationOffset: Int = 0,
 
    startIndex: Int = 0,
 
    endIndex: Int = length
 
): CharArray
 
</syntaxhighlight>'''بيئة التشغيل المطلوبة: JVM'''
 
 
 
تنسخ الدالة <code>toCharArray()</code>‎  حروف [[Kotlin/String|السلسلة النصية]] التي استٌدعيت عبرها في المصفوفة المُمرّرة <code>destination</code> ابتداء من الفهرس المحدد<code>destinationOffset</code> ثم تعيد تلك المصفوفة. الوسيطان <code>startIndex</code> و <code>endIndex</code> يحددان الجزء الذي سيُنسخ من  [[Kotlin/String|السلسلة النصية]] الأصلية.
 
 
 
يُلاحَظ وجود الكلمة المفتاحية <code>inline</code> للدلالة على أن هذه الدالة مباشرة، وللمزيد من التفاصيل راجع <nowiki/>[[Kotlin/inline functions|توثيق الدوال المباشرة (inline functions)]].
 
 
== القيم المعادة ==
 
== القيم المعادة ==
مصفوفة من النوع <code>[[Kotlin/CharArray/index|CharArray]]</code>.
+
الوسيط المُمرّر <code>destination</code>.
  
 
== أمثلة ==
 
== أمثلة ==
 
=== استخدام الدالة <code>toCollection()‎</code> مع السلاسل النصية ===
 
=== استخدام الدالة <code>toCollection()‎</code> مع السلاسل النصية ===
الشيفرة الآتية <nowiki/>تستدعي الدالة <code>toCollection()‎</code> عبر عدة [[Kotlin/String|سلاسل نصية]]، وتطبع الناتج:<syntaxhighlight lang="kotlin">
+
تعرّف الشيفرة الآتية [[Kotlin/String|سلسلة نصية]] باسم <code>str</code> ولائحة حروف باسم <code>list</code>، ثم تستدعي الدالة <code>toCharArray()‎</code> عبر <code>str</code> وتمرر إليها <code>list</code>، ثم تطبع الناتج:<nowiki/><syntaxhighlight lang="kotlin">
 
fun main(args: Array<String>) {
 
fun main(args: Array<String>) {
println("wiki.hsoub.com".toCharArray().toList()) // [w, i, k, i, ., h, s, o, u, b, ., c, o, m]
+
val list : MutableList<Char> = mutableListOf()
println("3.14".toCharArray().toList()) // [3, ., 1, 4]
 
println("Aa".toCharArray().toList()) // [A, a]
 
}
 
</syntaxhighlight>
 
=== استخدام الدالة <code>toCharArray()‎</code> مع السلاسل النصية مع تمرير مصفوفة ===
 
تعرّف الشيفرة الآتية [[Kotlin/String|سلسلة نصية]] باسم <code>str</code> ومصفوفة من النو ع <code>[[Kotlin/CharArray/index|CharArray]]</code> باسم <code>array</code>، ثم تستدعي الدالة <code>toCharArray()‎</code> عبر <code>str</code> وتمرر إليها  المصفوفة <code>array</code>، ثم تطبع الناتج:<syntaxhighlight lang="kotlin">
 
fun main(args: Array<String>) {
 
val array = CharArray(14)
 
 
val str = "wiki.hsoub.com"   
 
val str = "wiki.hsoub.com"   
println(str.toCharArray(array).toList()) // [w, i, k, i, ., h, s, o, u, b, ., c, o, m]
+
   
 +
str.toCollection(list)
 +
   
 +
println(list) // [w, i, k, i, ., h, s, o, u, b, ., c, o, m]
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
== انظر أيضًا ==
 
== انظر أيضًا ==
 
* <code>[[Kotlin/text/toUpperCase|toUpperCase()]]</code>‎ : تحوّل الدالة <code>toUpperCase()</code>‎ الحرف أو السلسلة النصية التي استٌدعيت عبرها إلى حالة الأحرف الكبيرة (uppercase).
 
* <code>[[Kotlin/text/toUpperCase|toUpperCase()]]</code>‎ : تحوّل الدالة <code>toUpperCase()</code>‎ الحرف أو السلسلة النصية التي استٌدعيت عبرها إلى حالة الأحرف الكبيرة (uppercase).
سطر 50: سطر 32:
  
 
== مصادر ==
 
== مصادر ==
* [http://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/to-char-array.html صفحة الدالة text.toCollection()‎ في التوثيق الرسميّ للمكتبة القياسيّة في لغة Kotlin.]
+
* [http://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/to-collection.html صفحة الدالة text.toCollection()‎ في التوثيق الرسميّ للمكتبة القياسيّة في لغة Kotlin.]
 
[[تصنيف:Kotlin]]
 
[[تصنيف:Kotlin]]
 
[[تصنيف:Kotlin Method]]
 
[[تصنيف:Kotlin Method]]

مراجعة 11:29، 13 يوليو 2018

تضيف الدالة toCollection()‎ كل حروف سلسلة الحروف  التي استٌدعيت عبرها إلى الوسيط المُمرّر destination.

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

fun <C : MutableCollection<in Char>> CharSequence.toCollection(
    destination: C
): C

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

الوسيط المُمرّر destination.

أمثلة

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

تعرّف الشيفرة الآتية سلسلة نصية باسم str ولائحة حروف باسم list، ثم تستدعي الدالة toCharArray()‎ عبر str وتمرر إليها list، ثم تطبع الناتج:

fun main(args: Array<String>) {
val list : MutableList<Char> = mutableListOf()
val str = "wiki.hsoub.com"   
    
str.toCollection(list)
    
println(list) // [w, i, k, i, ., h, s, o, u, b, ., c, o, m]
}

انظر أيضًا

  • toUpperCase()‎ : تحوّل الدالة toUpperCase()‎ الحرف أو السلسلة النصية التي استٌدعيت عبرها إلى حالة الأحرف الكبيرة (uppercase).
  • isDefined(): تعيد القيمة true في حال كان الحرف (Unicode code point) الذي استٌدعيت عبره مُعرّفًا في اليونيكود (Unicode).

مصادر