سلاسل Groovy وGStrings
أتقن التعامل مع السلاسل في Groovy: علامات الاقتباس المفردة والمزدوجة والثلاثية، والاستيفاء في GString، والنصوص متعددة الأسطر لمهام البرمجة النصية.
سلاسل Groovy وGStrings درس مجاني في Groovy & Gradle: JVM Automation and Build Engineering على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Groovy & Gradle: JVM Automation and Build Engineering، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Groovy & Gradle: JVM Automation and Build Engineering 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Strings in Groovy
Groovy gives you several string literals, each for a job. Picking the right one keeps scripts clean and dodges escaping headaches.
Single-Quoted Strings
Single quotes make a plain String with no interpolation — what you type is exactly what you get.
def s = 'Hello World'
println sDouble-Quoted GStrings
Double quotes make a GString: any expression inside ${...} is evaluated and dropped into the text.
def name = "Alice"
println "Hello, ${name}!"Simplified Interpolation
For a single variable you can skip the braces and just put a dollar sign before the name.
def user = "Bob"
println "Welcome $user"Expressions Inside GStrings
Any expression fits inside ${...} — method calls, arithmetic, whatever you need.
def a = 3, b = 4
println "Sum is ${a + b}"Triple-Quoted Strings
Triple single quotes give a multiline plain string — ideal for text blocks without escaping every newline.
def text = '''Line one
Line two
Line three'''
println textTriple Double Quotes
Triple double quotes are multiline and support interpolation — perfect for templated output.
def title = "Report"
def doc = """=== ${title} ===
Generated by Groovy"""
println docSlashy Strings
Slashy strings (between forward slashes) skip backslash escaping — great for regexes and file paths.
def pattern = /\d{4}-\d{2}/
println patternLazy GString Evaluation
A GString can embed a closure (${-> ...}) that re-evaluates on each render, capturing live values instead of a snapshot.
def count = 1
def g = "Count: ${-> count}"
count = 2
println gUseful String Methods
Groovy adds handy string methods like padLeft and reverse, plus easy slicing with index ranges.
def s = "Groovy"
println s.reverse()
println s[0..2]GString vs String Equality
A GString isn't a String, but they compare equal and auto-convert. Call toString() when the exact type matters, like map keys.
def k = "id_${1}".toString()
def m = [(k): "value"]
println m["id_1"]Quick Check
Test your Groovy string knowledge.
Recap
You mastered Groovy strings: plain vs GString, triple-quoted multiline, slashy strings for regex, and lazy ${-> ...} closures.
الأسئلة الشائعة
هل درس «سلاسل Groovy وGStrings» مجاني؟
نعم — نص درس «سلاسل Groovy وGStrings» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Groovy & Gradle: JVM Automation and Build Engineering، انتقل إلى CoddyKit PRO. تتضمن دورة Groovy & Gradle: JVM Automation and Build Engineering 4 دروس في المجموع.
ماذا ستتعلم في «سلاسل Groovy وGStrings»؟
أتقن التعامل مع السلاسل في Groovy: علامات الاقتباس المفردة والمزدوجة والثلاثية، والاستيفاء في GString، والنصوص متعددة الأسطر لمهام البرمجة النصية. تتمرن على Groovy & Gradle: JVM Automation and Build Engineering مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Groovy & Gradle: JVM Automation and Build Engineering؟
لا تُشترط خبرة سابقة. Groovy & Gradle: JVM Automation and Build Engineering على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «سلاسل Groovy وGStrings»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Groovy & Gradle: JVM Automation and Build Engineering هذا؟
نعم. كل درس في Groovy & Gradle: JVM Automation and Build Engineering يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- مقدمة إلى Groovy وJVM
- بنية Groovy النحوية والأنواع الأساسية
- برامج Groovy النصية وGShell
- سلاسل Groovy وGStrings