Arjun Thakur has Published 1025 Articles

What is the operator that concatenates two or more string objects in C#?

Arjun Thakur

Arjun Thakur

Updated on 22-Jun-2020 15:34:05

647 Views

Use operator + to concatenate two or more string objects.Set the first string object.char[] c1 = { 'H', 'e', 'n', 'r', 'y' }; string str1 = new string(c1);Now, set the second string object.char[] c2 = { 'J', 'a', 'c', 'k' }; string str2 = new string(c2);Now display the concatenated strings ... Read More

C# program to get the extension of a file in C#

Arjun Thakur

Arjun Thakur

Updated on 22-Jun-2020 15:03:30

302 Views

To handle file paths, the Path class is used in C#.Set the file name in a string −string myPath = "D:ew\quiz.txt";Now, to get the extension, use the GetExtension() method −Path.GetExtension(myPath)Here is the complete code −Example Live Demousing System; using System.IO; namespace Demo {    class Program {       static ... Read More

Environment.NewLine in C#

Arjun Thakur

Arjun Thakur

Updated on 22-Jun-2020 15:02:36

2K+ Views

The Enviornment.NewLine in C# is used to add newline.To set a new line in between words −str = "This is demo text!" + Environment.NewLine + "This is demo text on next line!";The following is the code −Example Live Demousing System; using System.IO; namespace Demo {    class Program {     ... Read More

Randomize string in C#

Arjun Thakur

Arjun Thakur

Updated on 22-Jun-2020 14:54:50

2K+ Views

To randomize string, firstly use Random class −Random r = new Random();Now, use the Next() method with OrderBy() −string random = new string(str.ToCharArray().OrderBy(s => (r.Next(2) % 2) == 0).ToArray());Here is the compete code that displays randomize string −Example Live Demousing System; using System.IO; using System.Linq; class Demo {    static void ... Read More

Replace parts of a string with C# Regex

Arjun Thakur

Arjun Thakur

Updated on 22-Jun-2020 14:52:47

2K+ Views

Set a string −string str = "Bit and Bat";Let’s say you need to replace whatever comes inside B and t to A and capitalize the complete string. For that, use Replace −Regex.Replace(str, "B.t", "BAT");Let us see the complete code −Example Live Demousing System; using System.Text.RegularExpressions; namespace Demo {    class Program ... Read More

C# Program to display a string in reverse alphabetic order

Arjun Thakur

Arjun Thakur

Updated on 22-Jun-2020 14:46:49

830 Views

Set a string array and convert it to character array −string str = "Amit"; char[] arr = str.ToCharArray();Now, use the Reverse method to display the above string in reverse alphabetic order −Array.Reverse(arr);Here is the complete code −Example Live Demousing System; using System.Linq; using System.IO; class Program {    static void Main() ... Read More

C# Program to split parts in a Windows directory

Arjun Thakur

Arjun Thakur

Updated on 22-Jun-2020 14:46:00

783 Views

Firstly, set a string i.e. your Windows directory path −string str = @"D:\Downloads\Amit";Now use the Split() method and split wherever the \ occur −str.Split(' \')The following is the complete code −Example Live Demousing System; class Program {    static void Main() {       string str = @"D:\Downloads\Amit";     ... Read More

Usage of CSS :focus pseudo-class

Arjun Thakur

Arjun Thakur

Updated on 22-Jun-2020 14:38:04

87 Views

You can try to run the following code to implement :focus pseudo-classExampleLive Demo                    input:focus {             background-color: orange;          }                              Subject          Student:          Age:                     Output

Get all drives in C#

Arjun Thakur

Arjun Thakur

Updated on 22-Jun-2020 14:31:43

670 Views

Firstly, use GetDrives to get the name of all the drives −var drv = DriveInfo.GetDrives();Loop through to get the name of all the drives on the system −foreach (DriveInfo dInfo in drv) {    Console.WriteLine(dInfo.Name); }Let us see the complete code −Example Live Demousing System; using System.Linq; using System.IO; public class ... Read More

Skip method in C#

Arjun Thakur

Arjun Thakur

Updated on 22-Jun-2020 14:30:05

6K+ Views

Use the Skip() method in C# to skip number of elements in an array.Let’s say the following is our array −int[] arr = { 10, 20, 30, 40, 50 };To skip the first two elements, use the Skip() method and add argument as 2 −arr.Skip(2);Let us see an example −Example Live ... Read More

Advertisements