Ankita Saini has Published 277 Articles

Swift Program to Iterate through each character of the string

Ankita Saini

Ankita Saini

Updated on 09-May-2023 10:52:12

In Swift, we can iterate through each character of the string very easily. For the iteration, Swift provides the following methods − Using for-in loop Using forEach() function Using enumerated() function Method 1: Using for-in loop We can use a for-in loop for the iteration. It iterates through ... Read More

Swift Program to Insert a string into another string

Ankita Saini

Ankita Saini

Updated on 09-May-2023 10:41:17

Swift provides a function named insert() to insert a string into another string. The insert(at:) function adds a new character or string in the current string at the specified position. Input String = “Program to learn” New String = “Swift” Output String = Swift Program to learn” Here ... Read More

Swift Program to Get key from Dictionary using the value

Ankita Saini

Ankita Saini

Updated on 09-May-2023 10:35:05

A dictionary is a collection of key-value pairs. Which means keys and values are interrelated with each other. So using a value we can easily get single or multiple keys from the given dictionary. Algorithm Step 1 − Create a dictionary with key-value pairs. Step 2 − Then create ... Read More

Swift Program to Find the Frequency of Characters in a String

Ankita Saini

Ankita Saini

Updated on 09-May-2023 10:31:24

In Swift, the frequency of all the characters in a string means how much time a character repeats in the given string. For example, “Swift tutorial”, here “t” repeats 3 times in the given string, “i” repeat 2 times in the given string. So in this article, we are going ... Read More

Swift Program to delete suffix substring from the given string

Ankita Saini

Ankita Saini

Updated on 09-May-2023 10:26:37

To delete the suffix substring from the given string first, we check if the given substring is present in the specified string or not using the inbuilt hasSuffix() function. Then find the index of the suffix substring using the inbuilt index() function and finally remove the suffix substring. Input String ... Read More

Swift Program to delete prefix substring from the given string

Ankita Saini

Ankita Saini

Updated on 09-May-2023 10:24:21

To delete the prefix substring from the given string first, we check if the given substring is present in the specified string or not using the inbuilt hasPrefix() function. Then find the index of the prefix substring using the inbuilt index() function and finally remove the prefix substring. Input String ... Read More

Swift Program to Create an Empty Dictionary

Ankita Saini

Ankita Saini

Updated on 09-May-2023 10:21:44

A dictionary is an unordered collection in which data is stored in the form of key-value pairs, where keys are the unique identifiers of any data type like string, integer, etc., that are connected with each value. In Swift, we are allowed to create an empty dictionary. An empty dictionary ... Read More

Swift Program to count a specified character inside the string

Ankita Saini

Ankita Saini

Updated on 09-May-2023 10:18:20

In Swift, to count how many times a specified character occurs in the given string we create a function. It will increase the value of the counter by one whenever the specified character appears in the given string and then return the final count at the end of the given ... Read More

Swift Program to convert the array of characters into the string

Ankita Saini

Ankita Saini

Updated on 09-May-2023 10:08:02

To convert the array of characters into a string Swift provides the following methods − Using String() initialiser Using append() method Input array = [“S”, “w”, “i”, “f”, “t”] Output Swift Here we join all the characters given in the array to create a string. Method ... Read More

Swift Program to check the given string is empty or not

Ankita Saini

Ankita Saini

Updated on 09-May-2023 10:03:05

To check if the given string is empty or not Swift provides an inbuilt property named as isEmpty. This property will return true if the given string is empty. And return false if the given string is not empty. Here empty string means whose length is 0 or we can ... Read More

Advertisements