Skip to main content
Skip to content

Lesson 10 of 12

Working with text: string built-ins

Clean up, cut, search and rebuild text with AltFLang's string helpers — and solve the palindrome puzzle.

10 min

Case and spaces

bada(s) ("big") makes text uppercase and chhota(s) ("small") lowercase. saaf(s) ("clean") removes spaces from both ends — perfect for tidying what a user typed. lambai(s) counts characters.

Expected output

Press Run to try it

RAHUL SHARMArahul sharma16 12

Split and join

kaato(text, separator) ("cut") splits text into a list wherever the separator appears. milao(list, separator) ("mix") does the reverse and glues a list into one string. Together they let you rebuild text in a new shape.

Expected output

Press Run to try it

[chai, samosa, jalebi]3 itemschai + samosa + jalebi

Search, replace and slice

shamil(text, part) checks whether text contains a part. khojo(text, part) returns where it starts, or -1. badlo(text, old, new) replaces every match. tukda(text, start, end) cuts characters from start up to, but not including, end. Character positions start at 0, just like list indexes.

Expected output

Press Run to try it

sahi 6Mujhe coffee pasand hai, coffee!Mujhe

Reverse it

ulta(text) ("reversed") returns the text backwards. A word that reads the same both ways is a palindrome, and checking one is now a single comparison.

Expected output

Press Run to try it

namansahi

Practice exercise

Turn the messy input " aaj ka DIN " into the title AAJ KA DIN: trim it, split on spaces, keep only non-empty words, and join with single spaces in uppercase. Print the result.

Expected output

AAJ KA DIN
Open in playground
Show solution
solution.altf
rakho text = "  aaj   ka DIN  ";
rakho words = kaato(saaf(text), " ");
rakho achhe = [];
chalo (rakho i = 0; i < lambai(words); i = i + 1) {
  agar (words[i] != "") {
    jodo(achhe, words[i]);
  }
}
bol(bada(milao(achhe, " ")));