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
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 enum by the string value. Syntax enum nameOfEnum: Type { case value1 case value2 case value3 } Let enumVariable = value Here, nameOfEnum represents the name of the enum, value1, value2, etc are values defined in the enum and ... Read More
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
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. In Swift, we are allowed to implement a switch statement on strings. Syntax switch (expression) { case 1: // Block of code case 2: // Block of code . . . default: // Block of code } Here, the switch statement evaluates the expression and executes only the ... Read More
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
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
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
In Swift, String interpolation is a great feature to create a new string by embedding the value of a variable, constant, function and literal directly in the given string literal. Or we can say that using string interpolation we can create a string by combining static text and dynamic values. Syntax var myString = “hello! \(x). How are you?” We can perform string interpolation by wrapping a string literal or constant or variable in a pair of parentheses that is prefixed by a backslash(\) for example, \(x). Example 1 In the following Swift program, we will demonstrate how ... Read More
In Swift, a random string is a sequence of characters. It is generated by randomly selecting characters from a set of available characters, for example: “fbbKDvf”, “dvsWFVsvdv”, etc. So to create random strings Swift provides the following methods − Using randomElement() method Using UUID Method 1: Using randomElement() method Swift provides an inbuilt function named as randomElement() method. This function returns a random element from the given sequence or collection. Syntax func randomElement() It returns random elements. If the given collection is empty, then it will return nil. Algorithm Step 1 − Create a ... Read More
Introduction The travel industry is constantly evolving, with increasing numbers of travelers seeking personalized experiences and seamless customer service. To meet these demands, travel companies must effectively manage and leverage traveler data. Salesforce, a leading customer relationship management (CRM) platform, offers powerful solutions for managing traveler data, enabling travel companies to deliver exceptional service and enhance customer satisfaction. In this article, we will explore how Salesforce can be used to manage traveler data, benefiting both travel companies and their customers. Understanding Salesforce for Travel Overview of Salesforce CRM − Salesforce is a cloud-based CRM platform that allows organizations to ... Read More