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

من موسوعة حسوب
اذهب إلى التنقل اذهب إلى البحث
(أنشأ الصفحة ب'<noinclude>{{DISPLAYTITLE: التابع text.toCollection()‎ في لغة Kotlin}}</noinclude> تعيد الدالة <code>toCollection()</code>‎ مصفوفة من ا...')
 
ط
 
(4 مراجعات متوسطة بواسطة مستخدمين اثنين آخرين غير معروضة)
سطر 1: سطر 1:
<noinclude>{{DISPLAYTITLE: التابع text.toCollection()‎ في لغة Kotlin}}</noinclude>
+
<noinclude>{{DISPLAYTITLE: الدالة <code>toCollection()‎</code> في Kotlin}}</noinclude>
تعيد الدالة <code>toCollection()</code>‎ مصفوفة من النوع <code>[[Kotlin/CharArray/index|CharArray]]</code> تحتوي حروف [[Kotlin/String|السلسلة النصية]] التي استٌدعيت عبرها.
+
تضيف الدالة <code>toCollection()</code>‎ كل محارف [[Kotlin/CharSequence|السلسلة]] التي استٌدعيت معها إلى [[Kotlin/collections/MutableCollection|المجموعة المتغيرة]] المُمرّرة إليها.
  
 
== البنية العامة ==
 
== البنية العامة ==
 
<syntaxhighlight lang="kotlin">
 
<syntaxhighlight lang="kotlin">
inline fun String.toCharArray(): CharArray
+
fun <C : MutableCollection<in Char>> CharSequence.toCollection(
 +
    destination: C
 +
): C
 +
</syntaxhighlight>
  
</syntaxhighlight>'''بيئة التشغيل المطلوبة: JVM'''
+
== المعاملات ==
 +
[[Kotlin/collections/MutableCollection|مجموعة متغيرة]] يراد أن يضاف فيها محتوى [[Kotlin/CharSequence|سلسلة المحارف]] المعطاة.
  
تعيد الدالة <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> بعد إضافة محتوى [[Kotlin/CharSequence|سلسلة المحارف]] المعطاة إليه.
  
 
== أمثلة ==
 
== أمثلة ==
=== استخدام الدالة <code>toCollection()‎</code> مع السلاسل النصية ===
+
مثالٌ على استعمال الدالة <code>toCollection()‎</code>:<nowiki/><syntaxhighlight lang="kotlin">
الشيفرة الآتية <nowiki/>تستدعي الدالة <code>toCollection()‎</code> عبر عدة  [[Kotlin/String|سلاسل نصية]]، وتطبع الناتج:<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]
+
    val str = "wikiHsoub"
println("Aa".toCharArray().toList()) // [A, a]
+
 
}
+
    str.toCollection(list)
</syntaxhighlight>
+
    println(list) // [w, i, k, i, H, s, o, u, b]
=== استخدام الدالة <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"  
 
println(str.toCharArray(array).toList()) // [w, i, k, i, ., h, s, o, u, b, ., c, o, m]
 
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
== انظر أيضًا ==
 
== انظر أيضًا ==
* <code>[[Kotlin/text/toUpperCase|toUpperCase()]]</code>‎ : تحوّل الدالة <code>toUpperCase()</code>‎ الحرف أو السلسلة النصية التي استٌدعيت عبرها إلى حالة الأحرف الكبيرة (uppercase).
+
*الدالة [[Kotlin/kotlin.text/toByteArray|<code>toByteArray()</code>]]: ترمز جميع محارف [[Kotlin/String|السلسلة النصية]] التي استٌدعيت معها وفقًا لترميز محدد ثم تضع الناتج في مصفوفة من النوع <code>[[Kotlin/ByteArray|ByteArray]]</code>.
 
+
*الدالة [[Kotlin/kotlin.text/toCharArray|<code>toCharArray()</code>‎]]: تضع جميع محارف [[Kotlin/String|السلسلة النصية]] التي استٌدعيت معها في مصفوفة من النوع <code>[[Kotlin/CharArray|CharArray]]</code>، إذ يوضع كل محرف في عنصر.
*<code>[[Kotlin/text/isDefined|toBigDecimalOrNull()]]‎</code>: تحلّل الدالة <code>toBigDecimalOrNull()</code>‎ [[Kotlin/String|السلسلة النصية]] التي استٌدعيت عبرها وتحوّلها إلى عدد من النوع <code>BigDecimal</code>.
 
*<code>[[Kotlin/kotlin.text/toBigDecimal|toBigDecimal()]]‎</code>: تحلّل الدالة <code>toBigDecimal()</code>‎ [[Kotlin/String|السلسلة النصية]] التي استٌدعيت عبرها وتحوّلها إلى عدد من النوع <code>BigDecimal</code>.
 
 
 
* <code>[[Kotlin/text/isDefined|isDefined()]]</code>: تعيد القيمة <code>true</code> في حال كان الحرف (Unicode code point) الذي استٌدعيت عبره مُعرّفًا في اليونيكود (Unicode).
 
  
 +
*الدالة <nowiki/>[[Kotlin/kotlin.text/toFloat|<code>toFloat()</code>‎]]: تحلّل السلسلة النصية التي استٌدعيت عبرها وتحوّلها إلى <nowiki/>[[Kotlin/Float|عدد عشري]].
 +
*الدالة <nowiki/>[[Kotlin/kotlin.text/toHashSet|<code>toHashSet()</code>‎]]: تحلّل كائنًا من النوع <code>HashSet</code> يحوي كل محارف <nowiki/>[[Kotlin/CharSequence/index|السلسلة]] التي استٌدعيت معها.
 +
*الدالة [[Kotlin/text/toLowerCase|<code>toLowerCase()</code>‎]]: تحول [[Kotlin/Char|المحرف]] أو جميع محارف [[Kotlin/String|السلسلة النصية]] التي استٌدعيت معها إلى محارف صغيرة (lowercase).
 +
*الدالة [[Kotlin/kotlin.text/toMutableList|<code>toMutableList()</code>‎]]: تضيف كل محارف [[Kotlin/CharSequence|سلسلة المحارف]] التي استٌدعيت معها إلى [[Kotlin/collections/List|قائمة متغيرة]]، إذ يوضع كل محرف في عنصر.
 +
*الدالة [[Kotlin/kotlin.text/toPattern|<code>toPattern()</code>‎]]: تحول [[Kotlin/String|السلسلة النصية]] التي استٌدعيت معها إلى نمط.
 +
*الدالة [[Kotlin/kotlin.text/toRegex|<code>toRegex()</code>‎]]: تحول [[Kotlin/String|السلسلة النصية]] التي استٌدعيت معها إلى [[Kotlin/kotlin.text/Regex/index|تعبير نمطي]] (regular expression). 
 +
*الدالة [[Kotlin/kotlin.text/toSet|<code>toSet()</code>‎]]: تضيف كل محارف [[Kotlin/CharSequence/index|سلسلة الحروف]]  التي استٌدعيت معها إلى مجموعة من النوع <code>[[Kotlin/Set|Set]]</code>، إذ يوضع كل محرف في عنصر.
 +
*الدالة [[Kotlin/kotlin.text/toSortedSet|<code>toSortedSet()</code>‎]]: تضيف كل محارف [[Kotlin/CharSequence|السلسلة]]  التي استٌدعيت معها إلى مجموعة من النوع <code>[[Kotlin/collections/SortedSet|SortedSet]]</code>، إذ يوضع كل محرف في عنصر.
 +
*الدالة [[Kotlin/kotlin.text/toString|<code>toString()</code>‎]] : تحول العدد الذي استٌدعي معها وفقًا لأساس مُحدّد إلى [[Kotlin/String|سلسلة نصية]].
 +
*الدالة [[Kotlin/text/toUpperCase|<code>toUpperCase()</code>‎]]: تحول [[Kotlin/Char|المحرف]] أو جميع محارف [[Kotlin/String|السلسلة النصية]] التي استٌدعيت معها إلى محارف كبيرة (uppercase).
 
== مصادر ==
 
== مصادر ==
* [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 صفحة الدالة toCollection()‎ في التوثيق الرسميّ للمكتبة القياسيّة في لغة Kotlin.]
 
[[تصنيف:Kotlin]]
 
[[تصنيف:Kotlin]]
[[تصنيف:Kotlin Method]]
+
[[تصنيف:Kotlin Function]]
 +
[[تصنيف:Kotlin Text]]

المراجعة الحالية بتاريخ 11:36، 6 سبتمبر 2018

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

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

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

المعاملات

مجموعة متغيرة يراد أن يضاف فيها محتوى سلسلة المحارف المعطاة.

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

يعاد المعامل destination بعد إضافة محتوى سلسلة المحارف المعطاة إليه.

أمثلة

مثالٌ على استعمال الدالة toCollection()‎:

fun main(args: Array<String>) {
    val list: MutableList<Char> = mutableListOf()
    val str = "wikiHsoub"

    str.toCollection(list)
    println(list) // [w, i, k, i, H, s, o, u, b]
}

انظر أيضًا

مصادر