Note If you don’t know how to solve an problem, or what is the function to be used, you could search on Internet for the answer using the API of the Java programming language. Indeed, since SARL is fully compatible with the Java API, you could use all the types or functions that are defined in this Java API.
Write a SARL program to calculate the length of a string, providing on the command line.
Write a SARL program to count the number of characters (character frequency) in a string.
google.com
{'g': 2, 'o': 3, 'l': 1, 'e': 1, '.': 1, 'c': 1, 'm': 1}
Write a SARL program to get a string made of the first 2 and last 2 characters of a given string (from the command line). If the string length is less than 2, return the empty string instead.
w3resource
w3ce
w3
w3w3
Write a SARL program to get a string from a given string (from the command line) where all occurrences of its first char have been changed to *
, except the first char itself.
restart
resta*t
Write a SARL program to get a single string from two given strings (from the command line), separated by a space and swap the first two characters of each string.
abc
, xyz
xyc abz
Write a SARL program to add ing
at the end of a given string (length should be at least 3). If the given string already ends with ing
, add ly
instead. If the string length of the given string is less than 3, leave it unchanged.
abc
abcing
string
stringly
Write a SARL program to find the first occurrence of the substrings not
and poor
in a given string. If not
follows poor
, replace the whole not
…poor
substring with good
. Return the resulting string.
The lyrics is not that poor!
and The lyrics is poor!
The lyrics is good!
and The lyrics is poor!
Write a SARL function that takes a list of words and return the longest word and the length of the longest one.
Write a SARL program to remove the nth index character from a nonempty string.
Write a SARL program to change a given string to a newly string where the first and last chars have been exchanged.
Write a SARL program to remove characters that have odd index values in a given string.
Write a SARL program to count the occurrences of each word in a given sentence.
Write a SARL script that takes input from the command line and displays that input back in upper and lower cases.
Write a SARL program that accepts a comma-separated sequence of words as command line input and prints the distinct words in sorted form (alphanumerically).
red, white, black, red, green, black
black
, green
, red
, white
, red
Write a SARL function to create an HTML string with tags around the word(s). Sample function and result:
['i', 'SARL']
gives <i>SARL</i>
['b', 'SARL Tutorial']
gives <b>SARL Tutorial</b>
Write a SARL function to insert a string in the middle of a string. Sample function and result :
('[[]]', 'SARL')
gives [[SARL]]
('', 'PHP')
gives ``Write a SARL function to get a string made of 4 copies of the last two characters of a specified string (length must be at least 2). Sample function and result :
SARL
gives RLRLRL
Exercises
-> eseseses
Write a SARL function to get a string made of the first three characters of a specified string. If the length of the string is less than 3, return the original string. Sample function and result :
ipy
gives ipy
SARL
gives SAR
Write a SARL function to reverse a string if its length is a multiple of 4.
Write a SARL function to convert a given string to all uppercase if it contains at least 2 uppercase characters in the first 4 characters.
Write a SARL program to sort a string lexicographically.
Write a SARL program to remove a newline in a string.
Write a SARL program to check whether a string starts with specified characters.
Write a SARL program to create a Caesar encryption.
Note In cryptography, a Caesar cipher, also known as Caesar’s cipher, the shift cipher, Caesar’s code or Caesar shift, is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. For example, with a left shift of 3, D would be replaced by A, E would become B, and so on. The method is named after Julius Caesar, who used it in his private correspondence.
Write a SARL program to remove existing indentation from all of the lines in a given text.
Write a SARL program to add prefix text to all of the lines in a string.
Write a SARL program to print the real numbers up to 2 decimal places.
Write a SARL program to print the real numbers up to 2 decimal places with a sign.
Write a SARL program to print the real positive and negative numbers with no decimal places.
Write a SARL program to print the integers with zeros to the left of the specified width.
Write a SARL program to print the integers with ‘*’ to the right of the specified width.
Write a SARL program to count occurrences of a substring in a string, both provided on the command line.
Write a SARL program to reverse a string that is provided on the command line.
Write a SARL program to reverse words in a string that is provided on the command line.
Write a SARL program to print the square and cube symbols in the area of a rectangle and the volume of a cylinder, using the string formatting tool of the API.
area = 1256.66
volume = 1254.725
decimals = 2
The area of the rectangle is 1256.66cm2
The volume of the cylinder is 1254.725cm3
Write a SARL program to print the index of a character in a string.
w3resource
Current character w position at 0
Current character 3 position at 1
Current character r position at 2
....
Current character c position at 8
Current character e position at 9
Write a SARL program to check whether a string contains all letters of the alphabet.
Write a SARL program to convert a given string into a list of words.
The quick brown fox jumps over the lazy dog.
['The', 'quick', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog.']
Write a SARL program to lowercase the first n characters in a string.
Write a SARL program to swap commas and dots in a string.
32.054,23
32,054.23
Write a SARL program to count and display vowels in text.
Write a SARL program to split a string on the last occurrence of the delimiter.
Write a SARL program to find the first non-repeating character in a given string.
Write a SARL program to print all permutations with a given repetition number of characters of a given string.
Write a SARL program to find the first repeated character in a given string.
Write a SARL program to find the first repeated character in a given string where the index of the first occurrence is smallest.
Write a SARL program to find the first repeated word in a given string.
Write a SARL program to find the second most repeated word in a given string.
Write a SARL program to remove spaces from a given string.
Write a SARL program to find all the common characters in lexicographical order from two given lower case strings. If there are no similar letters print No common characters
.
Write a SARL program to make two given strings (lower case, may or may not be of the same length) anagrams without removing any characters from any of the strings.
Write a SARL program to remove all consecutive duplicates of a given string.
Write a SARL program to find the longest common sub-string from two given strings.
Write a SARL program to count Uppercase, Lowercase, special characters and numeric values in a given string.
Write a SARL program to wrap a given string into a paragraph with a given width.
The quick brown fox.
10
The quick
brown fox.
Write a SARL program to swap cases in a given string.
SARL eXERiCISES
sarl ExerIcises
Write a SARL program to check whether a given string contains a capital letter, a lower case letter, a number and a minimum length.
Write a SARL program to convert a given heterogeneous list of scalars into a string. Sample Output:
['Red', 100, -50, 'green', 'w,3,r', 12.12, false]
Red,100,-50,green,w,3,r,12.12,false
Write a SARL program to extract numbers from a given string.
red 12 black 45 green
[12, 45]
Write a SARL program to replace each character of a word of length five and more with a hash character (#
).
Count the lowercase letters in the said list of words:
##### the ######### ####### in the said list of ######
Copyright © 2014-2024 SARL.io, the Original Authors and Main Authors.
Documentation text and medias are licensed under the Creative Common CC-BY-SA-4.0; you may not use this file except in compliance with CC-BY-SA-4.0. You may obtain a copy of CC-BY-4.0.
Examples of SARL code are licensed under the Apache License, Version 2.0; you may not use this file except in compliance with the Apache License. You may obtain a copy of the Apache License.
You are free to reproduce the content of this page on copyleft websites such as Wikipedia.
Generated with the translator docs.generator 0.14.0.