Ankita Saini has Published 319 Articles

Swift Program to convert an array into a string and join elements with a specified character

Ankita Saini

Ankita Saini

Updated on 19-Jul-2023 14:21:19

212 Views

In this article, we will learn how to write a swift program to convert an array into a string and join elements with a specified character. An array is used to store elements of same data type in an order. Here we use the following methods to join elements of ... Read More

Swift Program to get the flattened 1D array

Ankita Saini

Ankita Saini

Updated on 19-Jul-2023 14:19:52

235 Views

Swift has various functions like flatmap(), compactmap(), reduce() to flatten an 1D array. An array is used to store elements of same data type in an order whereas a set is used to store distinct elements of same data type without any definite order. Method 1: Using flatmap() Function To ... Read More

Swift Program to get the subarray from an array using a specified range of indices

Ankita Saini

Ankita Saini

Updated on 19-Jul-2023 14:14:13

557 Views

In swift, we have various methods like Array() initializer and for-in loop that can be used for getting the subarray from an array using a specified range of indices. An array stores elements of the same data type in an order. Let’s understand both the methods in detail in this ... Read More

Swift Program to Use Different Types of a Collection

Ankita Saini

Ankita Saini

Updated on 16-Jun-2023 12:28:26

102 Views

A collection is a group of elements or objects that are gathered together for some specific tasks. Swift supports three types of collections: Array, Set, and Dictionary. They are implemented as generic collections, also they are clear about what type of values they can store which means you can not ... Read More

Swift Program to Replace the Spaces of a String with a Specific Character

Ankita Saini

Ankita Saini

Updated on 16-Jun-2023 12:25:07

639 Views

In Swift, we are allowed to replace whitespaces with the specified character like $, *, ! etc. So, to replace the spaces of a string with a specific character swift provide the following methods − Using replacingOccurrences() method Using user-defined method Using components() and joined() methods Using split() and ... Read More

Swift Program to Reverse a String Using Stacks

Ankita Saini

Ankita Saini

Updated on 16-Jun-2023 12:16:42

607 Views

A stack is a data structure which works on LIFO(last in first out) principle. It is used to store and manage data where the recently added item is the first one to be removed from the stack. Stack support the following operations − Push − It is used to ... Read More

Swift Program to Sort a String

Ankita Saini

Ankita Saini

Updated on 16-Jun-2023 12:06:47

560 Views

In Swift, sorting of a string means arranging the characters of the string in the specified order either in ascending or descending order. For example − Input: String = "color of the bird is pink" Output:" bcdefhiiiklnoooprrst" Here, the resultant string is sorted in ... Read More

Swift Program to trim a string from both sides

Ankita Saini

Ankita Saini

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

159 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 ... Read More

Swift Program to trim a string from the left side

Ankita Saini

Ankita Saini

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

94 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 ... Read More

Swift Program to trim a string from the right side

Ankita Saini

Ankita Saini

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

89 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 ... Read More

Advertisements