Ankita Saini has Published 319 Articles

Swift Program to merge two integer arrays without using library function

Ankita Saini

Ankita Saini

Updated on 09-May-2023 10:56:28

90 Views

In Swift, we can merge two or more integer arrays without using the library function. So Swift provides an addition assignment(+=) operator to merge two integer arrays. Using this operator we will merge two arrays and assign the result into a new array. Syntax newArray += array Here, newArray ... Read More

Swift Program to Merge two Dictionaries

Ankita Saini

Ankita Saini

Updated on 09-May-2023 10:54:25

798 Views

To merge the content of two dictionaries Swift provides a pre-defined function named merging(_:uniqueKeysWith:). This function creates a new dictionary by merging the elements of two dictionaries. It also uses a combining closure to check the values for duplicate keys. Syntax func merging(otherDict){comClosure} This function takes two parameters ... Read More

Swift Program to Iterate through each character of the string

Ankita Saini

Ankita Saini

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

2K+ Views

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

376 Views

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

2K+ Views

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

410 Views

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

713 Views

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

469 Views

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

415 Views

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

833 Views

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

Previous 1 ... 5 6 7 8 9 ... 32 Next
Advertisements