Trim a String from Both Sides in Swift

Ankita Saini
Updated on 16-Jun-2023 12:01:35

383 Views

In Swift, we can adjust the size of the string by trimming some specified number of characters from both sides of the string. Or we can also trim the extra whitespaces which we do not want from both sides of the original string using the following methods. Method 1: Trim a string from the both sides To trim a specified number of characters or a substring from both sides of the string we create a user-defined function which takes an input string and the length of the characters which we wanted to remove from both sides of the original ... Read More

Trim a String from the Left Side in Swift

Ankita Saini
Updated on 16-Jun-2023 11:56:18

428 Views

In Swift, we can adjust the size of the string by trimming some specified number of characters from the left side of the string. Or we can also trim the extra whitespaces which we do not want on the left side of the original string using the following methods. Method 1: Trim a string from the left side To trim a specified number of characters or a substring from the left side of the string we create a user-defined function which takes an input string and the length of the characters which we wanted to remove from the left side ... Read More

Trim a String from the Right Side in Swift

Ankita Saini
Updated on 16-Jun-2023 11:51:25

259 Views

In Swift, we can adjust the size of the string by trimming some specified number of characters from the right-hand side of the given string. Or we can also trim the extra whitespaces which we do not want on the right-hand side of the given string using the following methods − Method 1: Trim a string from the right side To trim a specified number of characters or a substring from the right side of the string we create a user-defined function which takes an input string and the length of the characters which we wanted to remove ... Read More

Convert Celsius to Fahrenheit in Swift

Ankita Saini
Updated on 16-Jun-2023 11:31:14

1K+ Views

Fahrenheit is the commonly used temperature-measuring unit. In this scale, the freezing point and boiling point of the water are 32 degrees and 212 degrees. Whereas Celsius is also a temperature-measuring scale. In the Celsius scale, the freezing point and the boiling point of the water are 0 degrees and 100 degrees. So in Swift, we can convert Celsius to Fahrenheit using the following methods − Using Formula Using converted() method Method 1: Using Formula We can easily convert Celsius to Fahrenheit using the mathematical formula. It is the easiest way to convert Celsius to Fahrenheit. Syntax ... Read More

Convert Fahrenheit to Celsius in Swift

Ankita Saini
Updated on 16-Jun-2023 11:23:45

845 Views

Fahrenheit is the commonly used temperature-measuring unit. In this scale, the freezing point and boiling point of the water are 32 degrees and 212 degrees. Whereas Celsius is also a temperature-measuring scale. In the Celsius scale, the freezing point and the boiling point of the water are 0 degrees and 100 degrees. So in Swift, we can convert Fahrenheit to Celsius using the following methods − Using Formula Using converted() method Method 1: Using Formula We can easily convert Fahrenheit to Celsius using the mathematical formula. It is the easiest way to convert Fahrenheit to Celsius. ... Read More

Find the Longest Word in a String using Swift

Ankita Saini
Updated on 15-Jun-2023 17:03:32

722 Views

In Swift, a string is a sequence of characters. So a string can contain small and larger words. Hence using the following methods we can find the largest word in the string. Using component() method Using user-defined method Example Input String: "Rabbit run fast" Output String: "Rabbit" Here, the largest word among all the given words in the string is “Rabbit”. Method 1: Using component() method The components() method is used to create an array of substrings from the given string, where each substring is separated by the specified separator. So here we use the components(separatedBy:.whitespaces) method ... Read More

Tweening and Animating HTML5 and JavaScript Properties with Tween.js

Mukul Latiyan
Updated on 15-Jun-2023 16:56:36

687 Views

Tween.js is a JavaScript library that is mainly used when we want to tween or animate an HTML5 or JavaScript property. It can work standalone as well as when integrated with Easel.js. In this tutorial, we will learn how we can make use of Tween.js with the help of a few examples. Before we go on to the main example, let's first discuss a few simple tweens so that when we use them in the main example, you don't get overwhelmed. Simple Tween In this tween, we will tween the alpha property of the target from 0 to 1 for ... Read More

Swift Program to Generate a Password

Ankita Saini
Updated on 15-Jun-2023 16:35:50

673 Views

A password is a combination of various characters of a specified length and is used to authenticate or gain access to the system or login to an account. It is designed for security purposes and ensures that only an authorized user can access or log in to the specific account. It is important to select a strong password so that other people cannot crack it. It is generated according to the following conditions − Contains at least one uppercase letter. Contains at least one lowercase letter. Contains at least one number. Length must be 8 characters Contains at ... Read More

Add Animations to a Webpage Using Velocity.js

Mukul Latiyan
Updated on 15-Jun-2023 16:19:30

479 Views

Animations have become a very integral part of website interfaces in today's web development world. They help in enhancing the user experience of a website and in this article, we will learn how we can make use of Velocity.js to add beautiful animations to our web pages. VelocityJS is a JavaScript animation engine that provides us with very fast performing animations that we can use in our web pages. It has become one of the leading animation engines and there are different reasons for its success. I have mentioned some of the most important reasons that make it a very ... Read More

Generate OTP in Swift

Ankita Saini
Updated on 15-Jun-2023 16:16:30

637 Views

An OTP is known as a one-time password. It is an automatically generated random numeric string which is used for a single login session or transaction on digital devices. It is generally used to enhance security by providing extra authentication. For example, “423193”, “489201’, etc. To generate OTP Swift provides the following methods − Using random() method Using randomElement() method Method 1: Using random() method As we know that OTP is a randomly generated string. So to generate a random string Swift provide an inbuilt function named as random(). It is used to create a random string of ... Read More

Advertisements