LESSON 10 OF 52 · CHAPTER 01

Unicode Text

Text length, byte count, code points and searches

ORIGINAL SOURCE

10-unicode-text.srp

bind text: string = "café 🌍";
print(text_len(text), text_bytes(text), text_codepoint(text, 5));
print(text_find(text, "🌍"), text_contains(text, "é"));
print(text_starts_with(text, "caf"), text_ends_with(text, "🌍"));
EXPECTED OUTPUT

stdout

Verified
6 10 127757
5 true
true true

UNDERSTAND THE CODE

Explanation & practice

What this example teaches

Text length, byte count, code points and searches

Expected behavior

6 10 127757, 5 true, true true

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_len तथा text_bytes की संख्याएँ अलग हो सकती हैं। टेक्स्ट खोजने और अक्षर का कोड पॉइंट पढ़ने वाली सुविधाएँ भी दिखाई गई हैं।

अभ्यास: café 🌍 में अक्षरों और UTF-8 बाइट की गिनती क्यों अलग है?

Explanations are sourced from the project's English chapter guide and हिन्दी अध्याय. The Scarp program and output are unchanged.

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/10-unicode-text.srp scarp exec examples/01-basics/10-unicode-text.srp

The website does not run code. Read the CLI guide ↗

Pinned compiler: Scarp v0.0.6-alpha.3 · ceff07d9014f. No simulated output.