Ankita Saini has Published 319 Articles

Swift Program to check a string contains a specified substring or not

Ankita Saini

Ankita Saini

Updated on 14-Jun-2023 14:28:31

648 Views

In Swift, a substring is a small sequence of characters present in the large string, for example, “Car color is blue”, then “Car”, “color”, “is”, and “blue” are the substrings of the given string. Swift provides the following methods to check if the string contains the specified substring or not ... Read More

Swift Program to Remove All Whitespaces from a String

Ankita Saini

Ankita Saini

Updated on 14-Jun-2023 12:23:59

3K+ Views

A whitespace character is a non-printable character which represents a space in the string. To remove all the whitespaces from a string Swift provides the following methods − Using isWhitespace Property Using component() function Using replacingOccurrences(of:with:) method Using regular expressions Method 1: Using isWhitespace Property isWhitespace property is ... Read More

Swift Program to pad a string with 0's on the right side

Ankita Saini

Ankita Saini

Updated on 14-Jun-2023 11:37:27

453 Views

In Swift, pad a string with 0’s is to add 0 in the given string either on the left side or on the right side, for example, 234000 or 00021. Here we are going to pad a string with 0’s on the right side using the following methods − ... Read More

Swift Program to pad a string with 0's on left side

Ankita Saini

Ankita Saini

Updated on 14-Jun-2023 11:30:40

339 Views

In Swift, pad a string with 0’s is to add 0 in the given string either on the left side or on the right side, for example, 34000 or 0003232. Here we are going to pad a string with 0’s on the left side. Example Input: String = "151" ... Read More

Swift Program to Lookup enum by String value

Ankita Saini

Ankita Saini

Updated on 14-Jun-2023 11:23:35

142 Views

An enumeration or enum is a user-defined data type which holds a set of related values. It is defined by using the enum keyword. It is also known as an enum case because it uses case keywords to declare values inside it. In Swift, we are allowed to create an ... Read More

Swift Program to Implement the queue data structure

Ankita Saini

Ankita Saini

Updated on 14-Jun-2023 11:18:50

237 Views

A queue is a data structure which worked upon FIFO(first in first out) principle. In a queue, both ends are open, so that we can add a new element from one end called the rear or tail, this operation is known as enqueue and remove element from another end called ... Read More

Swift Program to Implement switch statement on Strings

Ankita Saini

Ankita Saini

Updated on 14-Jun-2023 10:51:25

351 Views

A switch statement is a control flow statement in which it only executes the block of code as soon as the expression given in the switch statement matches a case among the given multiple cases. If no case satisfies the given expression, then the switch statement executes the default case. ... Read More

Swift Program to Implement LinkedList

Ankita Saini

Ankita Saini

Updated on 13-Jun-2023 17:47:04

592 Views

A Linked list is a data structure which is used to store and manage data. It is a sequence of nodes where each not contains two things: data and the reference to the next node in the given sequence. Using a linked list we can easily insert or remove elements ... Read More

Swift Program to Get a Character From the Given String

Ankita Saini

Ankita Saini

Updated on 13-Jun-2023 17:42:46

95 Views

In Swift, we can easily get a character from the given string with the help of their respective index value. So to get the index of the specified character Swift provides an inbuilt function named index(). This function will return an index which is the specified distance from the specified ... Read More

Swift Program to Find the Duplicate Characters in a String

Ankita Saini

Ankita Saini

Updated on 13-Jun-2023 17:25:02

941 Views

In Swift, a string is a collection of characters so it can contain duplicate as well as unique characters. So to find the duplicate characters in a string we create a dictionary/array to store the count of each character and then add those characters in the array whose count is ... Read More

Advertisements