Strings in PSeInt: solved text exercises
12 examples
How it works
A string is a sequence of characters: letters, digits, spaces and symbols. In PSeInt it's stored in a Caracter variable and written in quotes.
The string functions do the heavy lifting: Longitud counts characters, SubCadena takes a piece, Concatenar joins two texts, Mayusculas and Minusculas change the case, and ConvertirANumero and ConvertirATexto go from text to number and back.
To look at a text letter by letter, combine a Para with SubCadena(texto, i, i). That's how you count vowels, reverse a word or check for a palindrome.
Short example
The least you need to see it work. Copy it or open it in the editor.
Algoritmo ReverseWord Definir palabra, invertida Como Caracter Definir i Como Entero Escribir "Type a word:" Leer palabra invertida <- "" Para i <- Longitud(palabra) Hasta 1 Con Paso -1 Hacer invertida <- invertida + SubCadena(palabra, i, i) FinPara Escribir "Reversed: ", invertidaFinAlgoritmoWhat it prints:
Type a word:User answer: codeReversed: edoc
Opens in the browser editor, nothing to install.
Solved exercises
Each exercise comes with the full code, its flowchart and a sample run.
Password Check
Keeps asking for a password until it has at least 8 characters.
BeginnerName Initials
Gets the initials of a full name.
BeginnerLinear Search
Finds a name in a list, ignoring upper and lower case.
IntermediatePalindromes
Checks whether a phrase reads the same forwards and backwards.
IntermediateCount Vowels
Counts the vowels, spaces and other characters in a text.
IntermediateData Formatting
Fixes upper and lower case, and converts between text and numbers.
IntermediateReusable Validation
Validates the email and age on a sign-up form.
IntermediateCaesar Cipher
Encrypts a message by shifting each letter of the alphabet.
AdvancedRoman Numerals
Converts a number from 1 to 3999 into Roman numerals.
AdvancedBase Conversion
Writes a number in binary and hexadecimal.
AdvancedHangman
Guess a secret word letter by letter, with six mistakes allowed.
AdvancedContact Book
Add, list and search contacts in a book that grows.
Advanced
In the language reference
The instructions involved, explained one by one.
Other concepts
Codoritmo is an independent, open-source project inspired by PSeInt and compatible with its syntax. It is not affiliated with the PSeInt project. Official PSeInt website.