Samual Sam has Published 2310 Articles

C# program to find the length of the Longest Consecutive 1’s in Binary Representation of a given integer

Samual Sam

Samual Sam

Updated on 22-Jun-2020 15:17:23

304 Views

To fetch the consecutive 1’s, use the Bitwise Left Shift Operator. Here is our decimal number.i = (i & (i

How to validate a URL using regular expression in C#?

Samual Sam

Samual Sam

Updated on 22-Jun-2020 15:15:44

2K+ Views

To validate, you need to check for the protocols.http httpsWith that, you need to check for .com, .in, .org, etc.For this, use the following regular expression −(http|http(s)?://)?([\w-]+\.)+[\w-]+[.com|.in|.org]+(\[\?%&=]*)?The following is the code −Example Live Demousing System; using System.Text.RegularExpressions; namespace RegExApplication {    class Program {       private static void showMatch(string ... Read More

Removing whitespaces using C# String.Empty

Samual Sam

Samual Sam

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

327 Views

Set the string.StringBuilder str = new StringBuilder("Tom Hanks");Now, use the replace() method to replace whitespace with String. Empty. This will eventually remove the whitespace.str.Replace(" ", String.Empty);Let us see the complete code −Example Live Demousing System; using System.Text; class Demo {    static void Main() {       StringBuilder str = ... Read More

Manipulate decimals with numeric operators in C#

Samual Sam

Samual Sam

Updated on 22-Jun-2020 14:56:09

231 Views

With C#, you can manipulate decimals with operators such as _+, - *, etc.Let us see how to subtract decimal values.Firstly, set two decimal values −decimal d1 = 9.5M; decimal d2 = 4.2M;Now to subtract the two values −d1 = d1 - d2;The following is the code −Example Live Demousing System; ... Read More

C# Program to check if a character is a whitespace character

Samual Sam

Samual Sam

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

347 Views

Set a character with WhiteSpace −char c = ' ';To check if a character is a whitespace character, use the char.IsWhiteSpace method −if (char.IsWhiteSpace(c)) {}Let us see the complete code −Example Live Demousing System; class Demo {    static void Main() {       char c = ' ';   ... Read More

C# program to check whether two sequences are the same or not

Samual Sam

Samual Sam

Updated on 22-Jun-2020 14:51:28

178 Views

The SequenceEqual method is used to test collections for equality.Set sequences −string[] arr1 = { "This", "is", "it" }; string[] arr2 = { "My", "work", "report" }; string[] arr3 = { "This", "is", "it" };Now, use the SequenceEquals methods to check whether sequences are same or not −arr1.SequenceEqual(arr2);The following is ... Read More

Bool.parse method in C#

Samual Sam

Samual Sam

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

162 Views

To convert a string to a bool, use the Bool.parse method in C# −Firstly, set a string −string str = "true";Now, convert it to bool −bool.Parse(str);Here is the complete code −Example Live Demousing System; using System.Linq; class Demo {    static void Main() {       string str = "true"; ... Read More

C# program to remove all the numbers after decimal places

Samual Sam

Samual Sam

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

4K+ Views

Use the Truncate method in C# to remove all the number after decimal places.Let’s say the following is our number −9.15MTo remove the numbers after decimal places, use Truncate() −decimal.Truncate(9.15M)Let us see the complete code −Example Live Demousing System; using System.Linq; class Demo {    static void Main() {     ... Read More

C# Program to get the last access time of a file

Samual Sam

Samual Sam

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

786 Views

To get the last access time of a file in C#, use the LastAccessTime() method.For this, use the FileInfo as well as DateTime classes.Create an object of each −FileInfo file = new FileInfo("new.txt"); DateTime dt = file.CreationTime; dt = file.LastAccessTime;Let us see the complete code −Example Live Demousing System.IO; using System; ... Read More

Lowercase suffixes in C#

Samual Sam

Samual Sam

Updated on 22-Jun-2020 14:42:40

154 Views

Set lowercase suffixes for literals such as u, l, ul, f, etc.// l for long long a = 29876l;It can be used on literal numbers as well. It tells the compiler that the literal is of a specific type.The following is an example −Example Live Demousing System.IO; using System; public class ... Read More

Advertisements