Strings & Methods
Strings in Djazair are immutable sequences of UTF-8 encoded characters. They support string interpolation, raw multiline backtick blocks, and more than 30 built-in manipulation methods.
String Literals & Interpolation
Strings can be enclosed in double quotes "..." or backticks `...`. Any valid Djazair expression can be evaluated inside ${...}:
djazair
let name = "Riad"
let age = 25
# String interpolation
let message = "Hello, my name is ${name} and in 5 years I will be ${age + 5}."
print(message)
# => Hello, my name is Riad and in 5 years I will be 30.
# Multiline Strings with backticks
let htmlTemplate = `
<div class="card">
<h2>${name}</h2>
<p>Age: ${age}</p>
</div>
`
print(htmlTemplate)
Complete String Methods Catalog
| Method | Signature | Description | Example |
|---|---|---|---|
length() | s.length() | Number of UTF-8 characters | "مرحبا".length() # => 5 |
upper() | s.upper() | Converts to uppercase | "dz".upper() # => "DZ" |
lower() | s.lower() | Converts to lowercase | "HELLO".lower() # => "hello" |
strip() | s.strip() | Trims leading/trailing whitespace | " hi ".strip() # => "hi" |
lStrip() / rStrip() | s.lStrip() | Trims left or right whitespace | " hi".lStrip() # => "hi" |
split(sep?) | s.split(sep?) | Splits string into an Array | "a,b,c".split(",") # => ["a","b","c"] |
join(array) | s.join(arr) | Joins array elements using separator | "-".join(["a","b"]) # => "a-b" |
replace(from, to) | s.replace(old, new) | Replaces occurrences of substring | "foo".replace("o","a") # => "faa" |
contains(sub) | s.contains(sub) | Returns True if substring exists | "djazair".contains("jaz") # => True |
startsWith(sub) | s.startsWith(sub) | Checks if string starts with prefix | "http://".startsWith("http") # => True |
endsWith(sub) | s.endsWith(sub) | Checks if string ends with suffix | "doc.pdf".endsWith(".pdf") # => True |
index(sub) | s.index(sub) | Index of substring (-1 if not found) | "hello".index("ll") # => 2 |
slice(start, end?) | s.slice(start, end) | Slice between start and end index | "Djazair".slice(0, 4) # => "Djaz" |
subStr(start, len) | s.subStr(start, len) | Substring with given length | "Djazair".subStr(1, 3) # => "jaz" |
reverse() | s.reverse() | Returns reversed string | "abc".reverse() # => "cba" |
capitalize() | s.capitalize() | Capitalizes first character | "algiers".capitalize() # => "Algiers" |
title() | s.title() | Title-cases every word | "hello world".title() # => "Hello World" |
swapCase() | s.swapCase() | Inverts letter cases | "AbC".swapCase() # => "aBc" |
center(width, pad?) | s.center(w, pad) | Centers string in given width | "dz".center(6, "-") # => "--dz--" |
lJust() / rJust() | s.lJust(w, pad) | Pads string on right or left | "5".lJust(3, "0") # => "500" |
zFill(width) | s.zFill(width) | Pads with leading zeroes | "42".zFill(5) # => "00042" |
charCodeAt(index) | s.charCodeAt(idx) | Returns character Unicode code-point | "A".charCodeAt(0) # => 65 |
isAlpha() | s.isAlpha() | Checks if purely alphabetic | "abc".isAlpha() # => True |
isDigit() | s.isDigit() | Checks if purely numeric digits | "123".isDigit() # => True |
isAlnum() | s.isAlnum() | Checks if alphanumeric | "a1".isAlnum() # => True |
isSpace() | s.isSpace() | Checks if whitespace-only | "
".isSpace() # => True |