LESSON 16 OF 52 · CHAPTER 01
Text Construction
text_concat, Unicode-scalar text_slice, text_repeat, length vs UTF-8 bytes
16-text-construction.srp
bind greeting: string = text_concat("Hello, ", "🌍");
bind planet = text_slice(greeting, 7, 1);
print(greeting);
print(text_repeat(planet, 3));
print(text_len(greeting), text_bytes(greeting));
stdout
Hello, 🌍
🌍🌍🌍
8 11
Write what you expect this program to print. Check prediction for a line-level hint without revealing the answer, or reveal the verified output when ready. This checks displayed text only; it does not run Scarp or save your input.
UNDERSTAND THE CODE
Explanation & practice
What this example teaches
text_concat, Unicode-scalar text_slice, text_repeat, length vs UTF-8 bytes
Expected behavior
Hello, 🌍, 🌍🌍🌍, 8 11
Practice: Read the source before looking at the output. Predict the values and their order, then use the pinned compiler to execute this lesson and compare the exact fixture. Identify which operation produces the result.
Unicode स्ट्रिंग बनाना और काटना
इस नए पाठ में text_concat("Hello, ", "🌍") दो स्ट्रिंग जोड़ता है। text_slice(greeting, 7, 1) सातवें इंडेक्स से एक Unicode scalar चुनकर पृथ्वी वाला इमोजी निकालता है। text_repeat(planet, 3) उसे तीन बार दोहराता है। ये Scarp v0.0.5-alpha.3 में जाँचे गए स्ट्रिंग निर्माण फ़ंक्शन हैं—इनका अर्थ यह नहीं कि हर grapheme cluster या Unicode normalization सुविधा उपलब्ध है।
आउटपुट: पहली लाइन Hello, 🌍, दूसरी 🌍🌍🌍, और तीसरी 8 11 है। पहला अंक Unicode scalar की गिनती है; दूसरा UTF-8 बाइट की गिनती। इमोजी एक scalar है लेकिन चार UTF-8 बाइट लेता है।
अभ्यास: "Hello, 🌍" में आठ Unicode scalar और 11 बाइट क्यों हैं? text_slice(greeting, 7, 1) किस स्थान का मान चुनता है?
Explanations are sourced from the project's English chapter guide and हिन्दी अध्याय. The Scarp program and output are unchanged.
LEARNING PROGRESS
Keep your place
Mark this lesson complete when you are ready.
Only saved in this browser. No account or tracking.
TRY IT LOCALLY
Verify, then execute
Use the pinned compiler from the course root. Keep any imported _support files next to the source.
scarp verify examples/01-basics/16-text-construction.srp
scarp exec examples/01-basics/16-text-construction.srpThe website does not run code. Read the CLI guide ↗
CHAPTER 01 · LAST LESSON
Ready for your next step? · आगे क्या सीखें?
This is the final example in this chapter. Try its verified coding lab before moving on. Your lesson progress changes only when you mark a lesson complete.
Pinned compiler: Scarp v0.0.6-alpha.3
· ceff07d9014f. No simulated output.