In Swift, every numerical ASCII value has its corresponding and equivalent character value. To convert an ASCII value to its equivalent character, we use the UnicodeScalar()
function.
UnicodeScalar(asciiValue)
asciiValue
: This is the ASCII value we want to convert to a character.
This method returns a character that is the corresponding equivalent of the specified ASCII value.
import Swift; // Create some ASCII values var asciiVal1 = 968; var asciiVal2 = 402; var asciiVal3 = 65; var asciiVal4 = 85; // Convert the ASCII values to a characters var char1 = UnicodeScalar(asciiVal1)! var char2 = UnicodeScalar(asciiVal2)! var char3 = UnicodeScalar(asciiVal3)! var char4 = UnicodeScalar(asciiVal4)! // Print the converted characters print("Char: ",char1); print("Char: ",char2); print("Char: ",char3); print("Char: ",char4);
UnicodeScalar()
method.RELATED TAGS
CONTRIBUTOR
View all Courses