Convert all letters of a Swift string to uppercase
This tutorial is based on the task to convert a given Swift string into uppercase with the help of Swift programming.
Sometimes we unknowingly type the text and after analyzing we find that the case we used was inappropriate. In this situation, if the given text is lengthy, it is quite difficult for a human to change the case manually. To overcome this situation, there is a function uppercased()
which will convert your given string into uppercase all in one go.
We will create a string in Swift as-
var string1="CodeSpeedy has a lot of informative articles."
It has created a string named string1
with this string. Now we need to uppercase all the letters in this Swift string. Below is how we are doing it:
var result=string1.uppercased()
This snippet has converted all the lowercase strings into uppercase and returned the string which is stored in the result variable. Print the output-
print(result)
So we have the result printed on the screen as-
CODESPEEDY HAS A LOT OF INFORMATIVE ARTICLES.
Here is the complete executable code-
var string1="CodeSpeedy has a lot of informative articles." var result=string1.uppercased() print(result)
This article has information regarding changing the case of text, particularly, from lower to upper. Also, there will be no change in the functioning if there are certain numbers present in the strings.
Thanks for reading! I hope this article was helpful. Stay connected for more such content.
Leave a Reply