Found 26504 Articles for Server Side Programming

C# Program to Search Sub-Directory in a Given Directory

Sabid Ansari
Updated on 04-May-2023 13:52:41

516 Views

Searching for sub-directories in a given directory is a common task in many applications. In C#, we can use the Directory and DirectoryInfo classes provided by the System.IO namespace to perform this task. In this article, we will explore how to write a C# program to search for sub-directories in a given directory. Method: Using DirectoryInfo.GetDirectories() The simplest way to search for sub-directories in a given directory is by using the DirectoryInfo.GetDirectories() method. This method returns an array of DirectoryInfo objects that represent the directories within a specified directory. Here's how we can use the DirectoryInfo.GetDirectories() method to search for ... Read More

Swift Array Check if an index exists

Nitin Aggarwal
Updated on 04-May-2023 12:19:21

4K+ Views

In Swift, there are several ways to check whether an index exists in an array. You can use startIndex, endIndex, the indices property, and the count property. In this article, you will see some examples of checking an index. Example 1: Using FirstIndex & EndIndex You can check if a specific index exists in a Swift array by comparing the index against the startIndex and endIndex properties of the array. Here's an example. import Foundation let inputArray = [1, 2, 3, 4, 5] let targetIndex = 3 if targetIndex >= inputArray.startIndex && targetIndex < inputArray.endIndex { print("Index ... Read More

Return multiple values from a function in Swift

Nitin Aggarwal
Updated on 04-May-2023 12:17:47

3K+ Views

In Swift, you can return multiple values from a function using a tuple. In this article, you will see different examples of how to use a tuple to return multiple values from a function. Here are some more practical examples of functions that return multiple values using tuples in Swift − Example 1 - Parsing a URL into its Components import Foundation func parseURL(urlString: String) -> (scheme: String, host: String, path: String) { guard let url = URL(string: urlString) else { fatalError("Invalid URL") } return ... Read More

C# Program to Search Directories and List Files

Sabid Ansari
Updated on 04-May-2023 13:51:28

28K+ Views

Searching directories and listing files is a common task in many applications. In C#, we can use the Directory and File classes provided by the System.IO namespace to perform these tasks. In this article, we will explore how to write a C# program to search directories and list files. Method: Using Directory.GetFiles() The simplest way to search directories and list files in C# is by using the Directory.GetFiles() method. This method returns an array of strings that represents the paths of all files in a specified directory that match a specified search pattern. Here's how we can use the Directory.GetFiles() ... Read More

Less than or greater than in the Swift switch statement

Nitin Aggarwal
Updated on 04-May-2023 12:16:05

3K+ Views

In Swift, there are many comparison operators to perform calculations and check different conditions. Less than or greater than operators are used to checking conditional statements. In this article, let's see how to use them with switch and if statements. Less Than or Greater Than the Switch Statement In Swift, you can use the case ..< and case ... syntax to define ranges in a switch statement. The case ..< syntax is used to define a range that includes all values greater than or equal to the first value and less than the second value Step 1 − If ... Read More

C# Program to Reverse the List of Cities using LINQ

Sabid Ansari
Updated on 04-May-2023 13:49:10

282 Views

In C#, LINQ (Language Integrated Query) is a powerful feature that allows us to perform queries on various data sources, including arrays, lists, and databases. It is an efficient and concise way to manipulate data and has become an essential tool for developers. In this article, we will explore how to use LINQ to reverse a list of cities in C#. Before we dive into the code, let us first understand what LINQ is. LINQ is a set of extensions to the .NET Framework that provides a standard way to query data from different data sources using a common syntax. ... Read More

C# Program to Reverse a String without using Reverse() Method

Sabid Ansari
Updated on 04-May-2023 13:47:44

8K+ Views

In programming, there are many situations where we need to reverse a string. One of the most common ways to do this is by using the Reverse() method. However, there are situations where we cannot use this method, and we have to reverse the string using other techniques. In this article, we will explore how to reverse a string in C# without using the Reverse() method. Before we dive into the code, let us first understand what a string is. A string is a sequence of characters that represents text. In C#, a string is a sequence of Unicode characters. ... Read More

C# Program to Read a String and Find the Sum of all Digits

Sabid Ansari
Updated on 04-May-2023 13:46:22

1K+ Views

C# is a popular object-oriented programming language used to develop Windows applications, web applications, and games. In this article, we will discuss how to write a C# program to read a string and find the sum of all digits present in the string. Step 1: Reading the Input String The first step in this program is to read the input string from the user. We can use the Console.ReadLine() method to read the string from the console. Here is an example − Console.WriteLine("Enter a string:"); string inputString = Console.ReadLine(); Step 2: Finding the Sum of Digits The next step ... Read More

How to get the name of the enumeration value in Swift?

Nitin Aggarwal
Updated on 04-May-2023 12:13:41

152 Views

In Swift, you can conform to the CustomStringConvertible protocol to provide a default name for each case in an enumeration. This protocol can be used to provide custom meaning as per the requirement. CustomStringConvertible CustomStringConvertible is a protocol in Swift that defines a single property, description, which returns a String representation of an instance of a conforming type. By conforming to CustomStringConvertible, you can customize how your types are represented as strings when they are printed, logged, or otherwise converted to a string. When you conform to CustomStringConvertible, you define how instances of your type are represented as strings by ... Read More

How should I remove all the leading spaces from a string in Swift?

Nitin Aggarwal
Updated on 04-May-2023 12:12:15

2K+ Views

In Swift, there are several approaches to removing the leading spaces from a string. There are some methods available like trimmingCharacters, drop, etc. You can also use the NSRegularExpression class to trim all leading spaces from a string. Using the trimmingCharacters() Method The trimmingCharacters(in:) method is a built-in method in Swift's String class that allows you to remove leading and/or trailing characters from a string. The method takes a single argument, which is a CharacterSet object that defines the set of characters to remove. You can create a CharacterSet object using the static properties of the CharacterSet class, such as ... Read More

Advertisements