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

من موسوعة حسوب
اذهب إلى التنقل اذهب إلى البحث
(أنشأ الصفحة ب'<noinclude>{{DISPLAYTITLE: التابع text.regionMatches()‎ في لغة Kotlin}}</noinclude> تعيد الدالة <code>regionMatches()</code>‎ القيمة <code...')
 
سطر 1: سطر 1:
 
<noinclude>{{DISPLAYTITLE: التابع text.regionMatches()‎ في لغة Kotlin}}</noinclude>
 
<noinclude>{{DISPLAYTITLE: التابع text.regionMatches()‎ في لغة Kotlin}}</noinclude>
تعيد الدالة <code>regionMatches()</code>‎ القيمة <code>true</code> إن طابقت [[Kotlin/String|السلسلة النصية]] أو [[Kotlin/CharSequence/index|سلسلة الحروف]] التي استٌدعيت عبرها التعبير النمطي المُمرّر <code>regex</code>.
+
تعيد الدالة <code>regionMatches()</code>‎ القيمة <code>true</code> إن طابقَ الجزءُ الذي يبدأ بالفهرس <code>thisOffset</code> وطوله <code>length</code> من [[Kotlin/String|السلسلة النصية]] أو [[Kotlin/CharSequence/index|سلسلة الحروف]] التي استٌدعيت عبرها الجزءَ المُحددَ المقابل الذي يبدأ بالفهرس <code>otherOffset</code> وطوله <code>length</code>في [[Kotlin/String|السلسلة النصية]] أو [[Kotlin/CharSequence/index|سلسلة الحروف]] المُمررة <code>other</code>،
 
==البنية العامة==
 
==البنية العامة==
 
<syntaxhighlight lang="kotlin">
 
<syntaxhighlight lang="kotlin">
fun String.matches(regex: String): Boolean
+
actual fun CharSequence.regionMatches(
 
+
    thisOffset: Int,
inline infix fun CharSequence.matches(regex: Regex): Boolean  
+
    other: CharSequence,
 
+
    otherOffset: Int,
 
+
    length: Int,
</syntaxhighlight>يُلاحَظ وجود الكلمة المفتاحية <code>inline</code> للدلالة على أن هذه الدالة مباشرة، وللمزيد من التفاصيل راجع <nowiki/>[[Kotlin/inline functions|توثيق الدوال المباشرة (inline functions)]].
+
    ignoreCase: Boolean = false
 +
): Boolean
  
 +
fun String.regionMatches(
 +
    thisOffset: Int,
 +
    other: String,
 +
    otherOffset: Int,
 +
    length: Int,
 +
    ignoreCase: Boolean = false
 +
): Boolean
 +
</syntaxhighlight>
 
==القيم المعادة==
 
==القيم المعادة==
 
قيمة منطقية.
 
قيمة منطقية.
 
==أمثلة==
 
==أمثلة==
 
===استخدام الدالة <code>regionMatches()‎</code> مع السلاسل النصية===
 
===استخدام الدالة <code>regionMatches()‎</code> مع السلاسل النصية===
تُعرّف الشيفرة الآتية [[Kotlin/String|سلسلتين نصيتين]] باسم <code>str</code> و <code>str2</code>، ثم تستدعي الدالة <code>regionMatches()‎</code> عبرهما وتمرر  [[Kotlin/String|سلسلة نصية]] كوسيط، ثم تطبع الناتج:<syntaxhighlight lang="kotlin">
+
تُعرّف الشيفرة الآتية [[Kotlin/String|سلسلتين نصيتين]] باسم <code>str</code> و <code>str2</code>، ثم تستدعي الدالة <code>regionMatches()‎</code> عبرهما وتمرر  عدة وسائط لتقارن بين جزئين منهما، ثم تطبع الناتج:<syntaxhighlight lang="kotlin">
 
fun main(args: Array<String>) {
 
fun main(args: Array<String>) {
val str = "sds12ff"  
+
val str = "abcradxyz"  
val str2 = "sdsff"  
+
val str2 = "mmradrt"  
 
      
 
      
print( str.matches ("""-?\d+(\.\d+)?""") ) // true
+
print( str.regionMatches (3, str2, 2, 3) ) // true
print( str2.matches ("""-?\d+(\.\d+)?""") ) // false
+
print( str.regionMatches (3, str2, 1, 3) ) // false
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 
==انظر أيضًا==
 
==انظر أيضًا==
 
*<code>[[Kotlin/kotlin.text/match|match()]]‎</code>: تعيد [[Kotlin/Array|مصفوفة]] مكونة من [[Kotlin/String|السلاسل النصية]] المُطابقة للتعبير النمطي المُمرّر <code>regex</code> في [[Kotlin/String|السلسلة النصية]] التي استٌدعيت عبرها.
 
*<code>[[Kotlin/kotlin.text/match|match()]]‎</code>: تعيد [[Kotlin/Array|مصفوفة]] مكونة من [[Kotlin/String|السلاسل النصية]] المُطابقة للتعبير النمطي المُمرّر <code>regex</code> في [[Kotlin/String|السلسلة النصية]] التي استٌدعيت عبرها.
*<code>[[Kotlin/kotlin.text/mapIndexed|mapIndexed()]]‎</code>: تعيد [[Kotlin/String|لائحة]] مكونة من نتائج تطبيق الدالة <code>transform</code> المُمرّرة  على عناصر [[Kotlin/CharSequence/index|سلسلة الحروف]] التي استٌدعيت عبرها وعلى فهارسها.
+
*<code>[[Kotlin/kotlin.text/matches|matches()]]‎</code>: تعيد الدالة <code>matches()</code>‎ القيمة <code>true</code> إن طابقت [[Kotlin/String|السلسلة النصية]] أو [[Kotlin/CharSequence/index|سلسلة الحروف]] التي استٌدعيت عبرها التعبير النمطي المُمرّر <code>regex</code>.
 
==مصادر==
 
==مصادر==
*[http://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/matches.html صفحة الدالة text.regionMatches()‎ في التوثيق الرسميّ للمكتبة القياسيّة في لغة Kotlin.]
+
*[http://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/region-matches.html صفحة الدالة text.regionMatches()‎ في التوثيق الرسميّ للمكتبة القياسيّة في لغة Kotlin.]
 
[[تصنيف:Kotlin]]
 
[[تصنيف:Kotlin]]
 
[[تصنيف:Kotlin Method]]
 
[[تصنيف:Kotlin Method]]

مراجعة 18:10، 11 يوليو 2018

تعيد الدالة regionMatches()‎ القيمة true إن طابقَ الجزءُ الذي يبدأ بالفهرس thisOffset وطوله length من السلسلة النصية أو سلسلة الحروف التي استٌدعيت عبرها الجزءَ المُحددَ المقابل الذي يبدأ بالفهرس otherOffset وطوله lengthفي السلسلة النصية أو سلسلة الحروف المُمررة other،

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

actual fun CharSequence.regionMatches(
    thisOffset: Int, 
    other: CharSequence, 
    otherOffset: Int, 
    length: Int, 
    ignoreCase: Boolean = false
): Boolean

fun String.regionMatches(
    thisOffset: Int, 
    other: String, 
    otherOffset: Int, 
    length: Int, 
    ignoreCase: Boolean = false
): Boolean

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

قيمة منطقية.

أمثلة

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

تُعرّف الشيفرة الآتية سلسلتين نصيتين باسم str و str2، ثم تستدعي الدالة regionMatches()‎ عبرهما وتمرر عدة وسائط لتقارن بين جزئين منهما، ثم تطبع الناتج:

fun main(args: Array<String>) {
val str = "abcradxyz" 
val str2 = "mmradrt" 
    
print( str.regionMatches (3, str2, 2, 3) ) // true
print( str.regionMatches (3, str2, 1, 3) ) // false
}

انظر أيضًا

مصادر