Skip to content
العربية

11. More about strings

To split a string, search it, and trim the spaces from both ends.

  • تقسيم(ن, فاصل) (split) splits the string into a list of strings at every place the separator appears.
  • قص_الفراغات(ن) (trim) returns the string without spaces at its start and end.
  • يحوي(ن, جزء) (contains) answers: does the part appear in the string? And يبدأ_بـ(ن, بادئة) (starts with) answers: does the string start with it?
Example
سطر = " تفاح، موز، عنب "
قطع = تقسيم(قص_الفراغات(سطر), "، ")
اطبع(قطع, " ", يحوي(سطر, "موز"), " ", يبدأ_بـ(قطع[0], "تف"))
Output recorded in the reference handbookmeem برنامج.م · 0.17.1
[تفاح, موز, عنب] صواب صواب

Try this example in the playground

Thinking that طول (length) counts bytes: it counts code points, and diacritics count too. A code point is the counting unit for strings (glossary).

Trim the spaces from both ends of « ميم لغة عربية صغيرة », split it into words, and print how many there are and the words that start with the letter «ع».

Show the solution
Solution
جملة = " ميم لغة عربية صغيرة "
كلمات = تقسيم(قص_الفراغات(جملة), " ")
اطبع("عدد الكلمات: ", طول(كلمات))
لكل ك في كلمات:
اذا يبدأ_بـ(ك, "ع"):
اطبع("تبدأ بالعين: ", ك)
حرر(كلمات)
Output recorded from the compilermeem 10_حل.م · meem 0.17.3+434e13f
عدد الكلمات: 4تبدأ بالعين: عربية

Types: the string · Builtins