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

من موسوعة حسوب
اذهب إلى التنقل اذهب إلى البحث
(أنشأ الصفحة ب'<noinclude>{{DISPLAYTITLE: التابع text.toHashSet()‎ في لغة Kotlin}}</noinclude> تحلّل الدالة <code>toHashSet()</code>‎ Kotlin/String|السل...')
 
سطر 1: سطر 1:
 
<noinclude>{{DISPLAYTITLE: التابع text.toHashSet()‎ في لغة Kotlin}}</noinclude>
 
<noinclude>{{DISPLAYTITLE: التابع text.toHashSet()‎ في لغة Kotlin}}</noinclude>
تحلّل الدالة <code>toHashSet()</code>‎ [[Kotlin/String|السلسلة النصية]] التي استٌدعيت عبرها وتحوّلها إلى عدد من النوع <code>[[Kotlin/Float/index|Float]]</code> وتعيد الناتج.
+
تعيد الدالة <code>toHashSet()</code>‎كائنًا من النوع <code>HashSet</code> يحتوي كل عناصر [[Kotlin/CharSequence/index|سلسلة الحروف]]  التي استٌدعيت عبرها.
 
 
في حال لم تكن [[Kotlin/String|السلسلة النصية]] تمثل عددًا فستطلق الدالةُ استثناءً <code>NumberFormatException</code>.
 
  
 
== البنية العامة ==
 
== البنية العامة ==
 
<syntaxhighlight lang="kotlin">
 
<syntaxhighlight lang="kotlin">
inline actual fun String.toFloat(): Float
+
fun CharSequence.toHashSet(): HashSet<Char>
 
 
</syntaxhighlight>يُلاحَظ وجود الكلمة المفتاحية <code>inline</code> للدلالة على أن هذه الدالة مباشرة، وللمزيد من التفاصيل راجع <nowiki/>[[Kotlin/inline functions|توثيق الدوال المباشرة (inline functions)]].
 
  
 +
</syntaxhighlight>
 
== القيم المعادة ==
 
== القيم المعادة ==
عدد من النوع <code>[[Kotlin/Float/index|Float]]</code>.
+
كائن من النوع <code>HashSet.</code>
  
 
== أمثلة ==
 
== أمثلة ==
سطر 18: سطر 15:
 
الشيفرة الآتية <nowiki/>تستدعي الدالة <code>toHashSet()‎</code> عبر عدة  [[Kotlin/String|سلاسل نصية]]، وتطبع الناتج:<syntaxhighlight lang="kotlin">
 
الشيفرة الآتية <nowiki/>تستدعي الدالة <code>toHashSet()‎</code> عبر عدة  [[Kotlin/String|سلاسل نصية]]، وتطبع الناتج:<syntaxhighlight lang="kotlin">
 
fun main(args: Array<String>) {
 
fun main(args: Array<String>) {
         println("43.1f".toFloat()) // 43.1
+
         println("hsoub".toHashSet()) // [h, b, s, u, o]
         println("32.87".toFloat()) // 32.87
+
         println("32.87".toHashSet()) // [8, 2, 3, ., 7]
         println("0.32f".toFloat()) // 0.32
+
         println("wiki".toHashSet()) // [i, k, w]
}
 
</syntaxhighlight>
 
=== استخدام الدالة <code>toFloat()‎</code> مع سلسلة نصية: الحالة الثانية ===
 
الشيفرة الآتية تستدعي الدالة <code>toFloat()‎</code> عبر [[Kotlin/String|سلسلة نصية]] غير صالحة:<syntaxhighlight lang="kotlin">
 
fun main(args: Array<String>) {
 
        println("43.1ff".toFloat()) // إطلاق استثناء
 
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
سطر 39: سطر 30:
  
 
== مصادر ==
 
== مصادر ==
* [http://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/to-float.html صفحة الدالة text.toHashSet()‎ في التوثيق الرسميّ للمكتبة القياسيّة في لغة Kotlin.]
+
* [http://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/to-hash-set.html صفحة الدالة text.toHashSet()‎ في التوثيق الرسميّ للمكتبة القياسيّة في لغة Kotlin.]
 
[[تصنيف:Kotlin]]
 
[[تصنيف:Kotlin]]
 
[[تصنيف:Kotlin Method]]
 
[[تصنيف:Kotlin Method]]

مراجعة 12:17، 13 يوليو 2018

تعيد الدالة toHashSet()‎كائنًا من النوع HashSet يحتوي كل عناصر سلسلة الحروف  التي استٌدعيت عبرها.

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

fun CharSequence.toHashSet(): HashSet<Char>

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

كائن من النوع HashSet.

أمثلة

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

الشيفرة الآتية تستدعي الدالة toHashSet()‎ عبر عدة سلاسل نصية، وتطبع الناتج:

fun main(args: Array<String>) {
        println("hsoub".toHashSet()) // [h, b, s, u, o]
        println("32.87".toHashSet()) // [8, 2, 3, ., 7]
        println("wiki".toHashSet()) // [i, k, w]
}

انظر أيضًا

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

مصادر