Articles on Trending Technologies

Technical articles with clear explanations and examples

How to Transfer Contacts from iPhone to iPhone?

Ankur Choudhury
Ankur Choudhury
Updated on 14-Jun-2023 575 Views

There was a time when we had to manually write in limitless quantities of phone numbers, names, and other information to transfer contacts from one mobile platform to another. Thanks to cell phones, which do most of the job for us in a short time. Nowadays, iPhones and Androids are the two most dominant smartphones on the market. Some individuals wish to migrate from Android to iPhone devices or from iPhone to Android smartphones or maybe from an older iPhone to their newly bought one, so they need to move their contact list from one phone to another in a ...

Read More

Swift Program to Print first letter of each word using regex

Ankita Saini
Ankita Saini
Updated on 14-Jun-2023 316 Views

In Swift, regex is known as a regular expression. It is used to create a pattern which helps in matching or extracting some specific port of the given string. We can create a regex instance with the help of a regular expression in regex literal or string. In this article, we are going to use regex to print the first letter of each word. Example Input: String = "Ram got first place" Output: "Rgfp " Here, the output string contains the first letters of each word present in the given string. In the following examples we are going to ...

Read More

Swift Program to demonstrate the example to write double-quotes in a string

Ankita Saini
Ankita Saini
Updated on 14-Jun-2023 619 Views

In Swift, a string is a sequence of characters that represent in between double quotes, for example: ”Learn Swift”, “tutorialspoint”, etc. But when you print the string double quotes were removed by the compiler and you will get Learn Swift, tutorialspoint in the output. So if you want to print double quotes in the output, then you have to place the backslash character or escape character(\) before the double quotes you want to print inside the given string. It tells the compiler that the character should be treated as a literal character, it is not part of string syntax. ...

Read More

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

Ankita Saini
Ankita Saini
Updated on 14-Jun-2023 2K+ 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 − Using range(of:) method Using contains() method Using Regex Method 1: Using range(of:) method The range(of:) method is used to find the range of the first occurrence of the given substring in the string. So using this method we can check if the given substring is present in ...

Read More

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

Ankita Saini
Ankita Saini
Updated on 14-Jun-2023 1K+ 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 − Using User-defined function Using pre-defined function Method 1: Using User-Defined Function To pad a string with 0’s on the right side we create a user-defined function which takes the input string and the total length of the resultant string as arguments and returns the resultant string. Example Input: String ...

Read More

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

Ankita Saini
Ankita Saini
Updated on 14-Jun-2023 1K+ 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" newLength = 6 Output: 000151 Here, we pad the original string with three zeros on the left side. Algorithm Step 1 − Create a function which takes the original string and the length of the new string as arguments. Step 2 − Calculates the total number of ...

Read More

Swift Program to Implement the queue data structure

Ankita Saini
Ankita Saini
Updated on 14-Jun-2023 650 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 the front or head, this operation is known as dequeue. Although Swift does not support any in-built queue data structure, still we can implement queue using various ways like link-list, structure, class, array, etc. You can use any of the methods to implement the queue data structure according to ...

Read More

Swift Program to Implement LinkedList

Ankita Saini
Ankita Saini
Updated on 13-Jun-2023 1K+ 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 from any position inside the list. Linked lists are of two types − Singly-linked list− It moves in only one direction because each node has a reference to the next node. But the next pointer of the last node points to NULL. Doubly linked list− It moves in ...

Read More

Swift Program to Get a Character From the Given String

Ankita Saini
Ankita Saini
Updated on 13-Jun-2023 370 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 index. Example Input: String = "Ram got first place" index = 5 Output: "o" Here, the given index value is 5 so the resultant character is “o”. Syntax func index(x:String.index, offsetBy: Int) Here, x is the valid index of the sequence and offsetBy is the ...

Read More

Swift Program to Find the Duplicate Characters in a String

Ankita Saini
Ankita Saini
Updated on 13-Jun-2023 2K+ 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 greater than 1. Example Input: “sky is pink” Output: Duplicate char: [“s”, “i”, “k”] Here, the input string contains three duplicate characters that are “s”, “i”, and “k”. To find the duplicate characters in a string we are going to use the following methods − User-defined function ...

Read More
Showing 36301–36310 of 61,297 articles
Advertisements