How to perform case conversion in Euphoria
Overview
Case conversion is a common function amongst all programing languages. In the same vein, Euphoria language has provision for converting an atom or sequence from uppercase to lowercase and vice versa.
To do this in Euphoria, we use two functions:
- The
lower()function - The
upper()function
The lower() function will convert an uppercase sequence or atom strings to lower case.
The upper() function will convert an uppercase sequence or atom strings to lower case.
Syntax
lowwer(value_to_converted)
upper(value_to_converted)
Parameter
This function takes the parameter, value_to_converted, which represents the string sequence.
Note: To use this function, we have to import the
text.efile from Euphoria’s core standard library into our program.
include std/text.e--declare some sequence variablesequence conv1, conv2, increase, decrease--assign valuesconv1 = "PINgING"conv2 = "changing"-- carry out case casting using lower and upper methodsdecrease = lower(conv1)increase = upper(conv2)--print outcome to outputprintf(1,"\"PINgING\" To lowercase: %s",{ decrease})printf(1,"\n\"changing\" To uppercase: %s",{increase})
Explanation
- Line 1: We include the
textfile. - Line 4: We declare the sequence to be used in the program.
- Lines 7–8: We assign values to already declared sequences.
- Lines 10–11: We call the
lower()andupper()method on variablesconv1andconv2, and save the output indecreaseandincreaserespectively. - Lines 13–14: We use
printfto print the output.