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

من موسوعة حسوب
اذهب إلى التنقل اذهب إلى البحث
(أنشأ الصفحة ب'<noinclude>{{DISPLAYTITLE: الدالة text.all()‎ في لغة Kotlin}}</noinclude> يختلف سلوك الدالة <code>all()‎</code> بحسب نوع وعدد ا...')
 
سطر 1: سطر 1:
 
<noinclude>{{DISPLAYTITLE: الدالة text.all()‎ في لغة Kotlin}}</noinclude>
 
<noinclude>{{DISPLAYTITLE: الدالة text.all()‎ في لغة Kotlin}}</noinclude>
يختلف سلوك الدالة <code>all()‎</code> بحسب نوع وعدد الوسائط المُمررة، انظر فقرة [[Kotlin/kotlin.text/String#.D8.A7.D9.84.D8.A8.D9.86.D9.8A.D8.A9 .D8.A7.D9.84.D8.B9.D8.A7.D9.85.D8.A9|البنية العامة]].  
+
تعبد الدالة <code>all()‎</code> القيمة  إن كانت كل الحروف تحقق الشرط المنطقي المُمرّر <code>predicate</code>.  
  
 
== البنية العامة ==
 
== البنية العامة ==
 
<syntaxhighlight lang="kotlin">
 
<syntaxhighlight lang="kotlin">
inline fun String(
+
inline fun CharSequence.all(
    bytes: ByteArray,
+
     predicate: (Char) -> Boolean
    offset: Int,
+
): Boolean
    length: Int,
+
</syntaxhighlight>
    charset: Charset
 
): String
 
</syntaxhighlight>'''بيئة التشغيل المطلوبة: JVM'''
 
 
 
تحول الدالة <code>String()‎</code> جزءًا من المصفوفة <code>bytes</code> (بداية من  العنصر ذو الفهرس <code>offset</code> وبطولٍ يساوي <code>length</code>) باستخدام مجموعة الحروف (character set) المُمرّرة <code>charset</code> وتعيد ناتج التحويل على شكل [[Kotlin/String|سلسلة نصية]].<syntaxhighlight lang="kotlin">
 
inline fun String(bytes: ByteArray, charset: Charset): String
 
 
 
</syntaxhighlight>'''بيئة التشغيل المطلوبة: JVM'''
 
 
 
تحول الدالة <code>String()‎</code>  المصفوفة <code>bytes</code>باستخدام مجموعة الحروف (character set) المُمرّرة <code>charset</code> وتعيد ناتج التحويل على شكل [[Kotlin/String|سلسلة نصية]].<syntaxhighlight lang="kotlin">
 
inline fun String(
 
     bytes: ByteArray,
 
    offset: Int,
 
    length: Int
 
): String
 
</syntaxhighlight>'''بيئة التشغيل المطلوبة: JVM'''
 
 
 
تحول الدالة <code>String()‎</code> جزءًا من المصفوفة <code>bytes</code> (بداية من  العنصر ذو الفهرس <code>offset</code> وبطولٍ يساوي <code>length</code>) باستخدام مجموعة الحروف  UTF-8 وتعيد ناتج التحويل على شكل [[Kotlin/String|سلسلة نصية]].<syntaxhighlight lang="kotlin">
 
inline fun String(bytes: ByteArray): String
 
 
 
</syntaxhighlight>'''بيئة التشغيل المطلوبة: JVM'''
 
 
 
تحول الدالة <code>String()‎</code>  المصفوفة <code>bytes</code>  باستخدام مجموعة الحروف  UTF-8 وتعيد ناتج التحويل على شكل [[Kotlin/String|سلسلة نصية]].<syntaxhighlight lang="kotlin">
 
inline actual fun String(chars: CharArray): String
 
 
 
 
 
</syntaxhighlight>تحول الدالة <code>String()‎</code> الحروف الموجودة في المصفوفة <code>chars</code> إلى [[Kotlin/String|سلسلة نصية]].<syntaxhighlight lang="kotlin">
 
inline actual fun String(
 
    chars: CharArray,
 
    offset: Int,
 
    length: Int
 
): String
 
</syntaxhighlight>تحول الدالة <code>String()‎</code>  الحروف الموجودة في المصفوفة <code>chars</code> (بداية من  العنصر ذو الفهرس <code>offset</code> وبطولٍ يساوي <code>length</code>) إلى [[Kotlin/String|سلسلة نصية]].<syntaxhighlight lang="kotlin">
 
inline fun String(
 
    codePoints: IntArray,
 
    offset: Int,
 
    length: Int
 
): String
 
</syntaxhighlight>'''بيئة التشغيل المطلوبة: JVM'''
 
 
 
تحول الدالة <code>String()‎</code>  نقاط الأكواد (code points) الموجودة في المصفوفة <code>codePoints</code> (بداية من  العنصر ذو الفهرس <code>offset</code> وبطولٍ يساوي <code>length</code>) إلى [[Kotlin/String|سلسلة نصية]].<syntaxhighlight lang="kotlin">
 
inline fun String(stringBuffer: StringBuffer): String
 
 
 
</syntaxhighlight>'''بيئة التشغيل المطلوبة: JVM'''
 
 
 
تحول الدالة <code>String()‎</code>  محتويات الكائن المُمرّر  <code>stringBuffer</code> إلى [[Kotlin/String|سلسلة نصية]].<syntaxhighlight lang="kotlin">
 
inline fun String(stringBuilder: StringBuilder): String
 
 
 
</syntaxhighlight>'''بيئة التشغيل المطلوبة: JVM'''
 
 
 
تحول الدالة <code>String()‎</code>  محتويات الكائن المُمرّر  <code>stringBuilder</code> إلى [[Kotlin/String|سلسلة نصية]].
 
 
 
 
== القيم المعادة ==
 
== القيم المعادة ==
[[Kotlin/String|سلسلة نصية]].
+
[[Kotlin/Boolean/index|قيمة منطقية]].
  
 
== أمثلة ==
 
== أمثلة ==

مراجعة 12:50، 7 يوليو 2018

تعبد الدالة all()‎ القيمة إن كانت كل الحروف تحقق الشرط المنطقي المُمرّر predicate.

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

inline fun CharSequence.all(
    predicate: (Char) -> Boolean
): Boolean

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

قيمة منطقية.

أمثلة

استخدام الدالةall()‎

ينشِئ التابع ByteArray()‎ في الشيفرة الآتية مصفوفةً باسم array مكونة من عشرة عناصر ، ثم نمرر array إلى الدالة all()‎ لتحويل جزء منها إلى سلسلة نصية، ثم نطبَع الناتج:

fun main(args: Array<String>) {
val f: (Int) -> Byte = { x -> (x+97).toByte() }
val array = ByteArray(10, f)
    
val x = String(array, 2, 6)

print(x) // cdefgh
}

انظر أيضًا

  • isDefined(): تعيد القيمة true في حال كان الحرف (Unicode code point) الذي استٌدعيت عبره مُعرّفًا في اليونيكود (Unicode).
  • الخاصية indices: تُستخدَم هذه الخاصيّة للحصول على الفهارس الصحيحة (valid indices) لسلسلة الحروف التي استُدعيت عبرها.

مصادر