Waxaan qoraynaa oon dib uhabeyn ku wadnaa docs oo af-soomaali ku qoran, ka qeybqaadasho raac lifaaqaan...Contribution guidelines

Strings in Soplang

Strings in Soplang are sequences of characters used to represent text. Soplang provides a rich set of operations and methods for working with strings, making text manipulation intuitive and powerful.

String Creation

In Soplang, strings can be created using single ' quotes, double " quotes, or triple ''' quotes for multi-line strings. The qoraal keyword is used for static typing of strings, which comes from the Somali word for "text".

String Literals

string_literals.sop
// String literals with single quotes
door single_quoted = 'Hello, Soplang!'

// String literals with double quotes
door double_quoted = "Hello, Soplang!"

// Multi-line strings with triple quotes
door multi_line = """This is a multi-line string.
It can span multiple lines.
No need for escape characters at line breaks."""

Empty and Special Strings

special_strings.sop
// Empty string
door empty = ""

// String with spaces
door spaces = "   "

// String with special characters
door special = "★ Soplang ★"

// Unicode characters
door unicode = "नमस्ते" // Hindi
door arabic = "مرحبا"   // Arabic
door somali = "Soo dhowow"  // Somali

Basic String Operations

Concatenation

Strings can be combined using the + operator.

string_concatenation.sop
// String concatenation
door first_name = "Mohamed"
door last_name = "Ali"

// Using + operator
door full_name = first_name + " " + last_name
qor(full_name)  // Mohamed Ali

// Concatenation with other types
door age = 30
door message = first_name + " is " + qoraal(age) + " years old"
qor(message)  // Mohamed is 30 years old

String Repetition

Strings can be repeated using the * operator.

string_repetition.sop
// String repetition
door star = "*"
door line = star * 10
qor(line)  // **********

// Useful for creating separators
door separator = "-" * 20
qor(separator)  // --------------------

// Combining repetition with concatenation
door header = "| " + "Title " + "|"
door border = "+" + "-" * (header.dherer() - 2) + "+"

qor(border)  // +-------+
qor(header)  // | Title |
qor(border)  // +-------+

String Methods

Soplang provides a rich set of methods for string manipulation. These methods do not modify the original string but return a new string.

Case Conversion

case_conversion.sop
// Case conversion methods
door text = "Soplang Programming Language"

// Converting to uppercase
door upper = text.kor_dhig()
qor(upper)  // SOPLANG PROGRAMMING LANGUAGE

// Converting to lowercase
door lower = text.yar_dhig()
qor(lower)  // soplang programming language

// Title case (capitalize first letter of each word)
door title = text.cinwaan_dhig()
qor(title)  // Soplang Programming Language

// Capitalize (only first letter of string)
door capitalized = "hello world".weyn_dhig_bilowga()
qor(capitalized)  // Hello world

Searching and Replacing

search_replace.sop
// String searching methods
door text = "Soplang is a programming language. Soplang is easy to learn."

// Find the position of a substring
door pos = text.raadi("programming")
qor(pos)  // 12

// Find the last occurrence
door last_pos = text.raadi_dambe("Soplang")
qor(last_pos)  // 35

// Count occurrences
door count = text.tiri("Soplang")
qor(count)  // 2

// Replacing substrings
door replaced = text.badal("Soplang", "SopLang")
qor(replaced)  // "SopLang is a programming language. SopLang is easy to learn."

// Replace only the first occurrence
door replaced_once = text.badal_hal("Soplang", "SopLang")
qor(replaced_once)  // "SopLang is a programming language. Soplang is easy to learn."

Trimming and Padding

trim_pad.sop
// Trimming whitespace
door text = "   Soplang   "

// Remove whitespace from both ends
door trimmed = text.jari()
qor("'" + trimmed + "'")  // 'Soplang'

// Remove whitespace from left side only
door left_trimmed = text.jari_bidix()
qor("'" + left_trimmed + "'")  // 'Soplang   '

// Remove whitespace from right side only
door right_trimmed = text.jari_midig()
qor("'" + right_trimmed + "'")  // '   Soplang'

// Padding strings
door word = "Soplang"

// Pad left with spaces to reach a total length
door left_padded = word.buuxi_bidix(10)
qor("'" + left_padded + "'")  // '   Soplang'

// Pad right with spaces
door right_padded = word.buuxi_midig(10)
qor("'" + right_padded + "'")  // 'Soplang   '

// Pad with a specific character
door zero_padded = word.buuxi_bidix(10, "0")
qor(zero_padded)  // 000Soplang

Splitting and Joining

split_join.sop
// Splitting strings
door sentence = "Soplang is easy to learn and use"

// Split by spaces
door words = sentence.kala_jar(" ")
qor(words)  // ["Soplang", "is", "easy", "to", "learn", "and", "use"]

// Split by a specific delimiter
door csv = "apple,banana,orange,mango"
door fruits = csv.kala_jar(",")
qor(fruits)  // ["apple", "banana", "orange", "mango"]

// Limit the number of splits
door limited = sentence.kala_jar(" ", 3)
qor(limited)  // ["Soplang", "is", "easy", "to learn and use"]

// Joining strings
door joined = " ".ku_biir(words)
qor(joined)  // "Soplang is easy to learn and use"

// Join with a different delimiter
door comma_joined = ", ".ku_biir(fruits)
qor(comma_joined)  // "apple, banana, orange, mango"

Checking String Properties

string_properties.sop
// String property checking methods

// Check if string starts with a prefix
door text = "Soplang Programming"
door starts_with_sop = text.ku_bilaabma("Sop")
qor(starts_with_sop)  // true

// Check if string ends with a suffix
door ends_with_ming = text.ku_dhammaada("ming")
qor(ends_with_ming)  // true

// Check if string consists of only alphabetic characters
door is_alpha = "Soplang".xarfo_kaliya()
qor(is_alpha)  // true

// Check if string consists of alphanumeric characters
door is_alnum = "Soplang123".xarfoabn_kaliya()
qor(is_alnum)  // true

// Check if string consists of only digits
door is_digit = "12345".abn_kaliya()
qor(is_digit)  // true

// Check if string is lowercase
door is_lower = "soplang".yar_kaliya()
qor(is_lower)  // true

// Check if string is uppercase
door is_upper = "SOPLANG".kor_kaliya()
qor(is_upper)  // true