C# Program to Match All the Digits in a String

George John
Updated on 22-Jun-2020 14:53:57

392 Views

To match all digits in a string, use C# Regex.Firstly, set a string with digits −string str = "These are my marks: 90 out of 100!";Use the following regular expression to get digits in a string −@"\d+"The following is the code −Example Live Demousing System; using System.Text.RegularExpressions; namespace Demo {    class Program {       private static void showMatch(string text, string expr) {          Console.WriteLine("The Expression: " + expr);          MatchCollection mc = Regex.Matches(text, expr);          foreach (Match m in mc) {             Console.WriteLine(m);   ... Read More

Style Every Checked Input Element with CSS

Giri Raju
Updated on 22-Jun-2020 14:53:19

207 Views

To style every checked element, use the CSS :checked selector. You can try to run the following code to implement the :checked selector −ExampleLive Demo                    input:checked {             height: 20px;             width: 20px;          }                     Fav sports:                Football          Cricket           Tennis          Tennis           Output

C# Program to Remove the End Part of a String

Chandu yadav
Updated on 22-Jun-2020 14:53:18

564 Views

Use the Regex.Replace method to remove the end part of a string in C#.The following is the string −string s1 = "Demo Text!";Now, let us say you need to remove the exclamation mark (!) from the string. For that just set it to empty using replace −System.Text.RegularExpressions.Regex.Replace(s1, "!", "");Here is the complete code −Example Live Demousing System; using System.Text.RegularExpressions; namespace Demo {    class Program {       static void Main(string[] args) {          string s1 = "Demo Text!";          // replace the end part          string s2 = System.Text.RegularExpressions.Regex.Replace(s1, "!", ... Read More

Replace Parts of a String with Regex in C#

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 {       static void Main(string[] args) {          string str = "Bit and Bat";          Console.WriteLine(str);          string res = Regex.Replace(str, "B.t", "BAT");          Console.WriteLine(res);       }    } }OutputBit and Bat BAT and BAT

Check If a Character Is a Whitespace Character in C#

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

366 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 = ' ';       if (char.IsWhiteSpace(c)) {          Console.WriteLine("Whitespace character!");       }    } }OutputWhitespace character!

Find Largest Element from an Array in C#

karthikeya Boyini
Updated on 22-Jun-2020 14:51:48

3K+ Views

Declare an array −int[] arr = { 20, 50, -35, 25, 60 };Now to get the largest element from an array, use the Max() method −arr.Max());Here is the complete code −Example Live Demousing System; using System.Linq; class Demo {    static void Main() {       int[] arr = { 20, 50, -35, 25, 60 };       Console.WriteLine(arr.Max());    } }Output60

Check If Two Sequences Are the Same in C#

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

184 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 an example −Example Live Demousing System; using System.Linq; class Program {    static void Main() {       string[] arr1 = { "This", "is", "it" };       string[] arr2 = { "My", "work", "report" };       string[] arr3 = { "This", "is", "it" };       bool res1 = arr1.SequenceEqual(arr2);       Console.WriteLine(res1);       bool res2 = arr1.SequenceEqual(arr3);       Console.WriteLine(res2);    } }OutputFalse True

CSS Position Fixed

George John
Updated on 22-Jun-2020 14:51:03

473 Views

The position: fixed; property allows you to position element relative to the viewport. You can try to run the following code to implement CSS position: fixed;ExampleLive Demo                    div{             position: fixed;             bottom: 0;             right: 0;             width: 200px;             border: 3px solid blue;          }                     position: fixed;       The position: fixed; property allows you to position element relative to the viewport.                div has position: fixed;           Output

Group By Operator in C#

karthikeya Boyini
Updated on 22-Jun-2020 14:51:03

188 Views

Use the group by the operator in C# to separate the results of an expression into parts.Let’s say the following is our array −int[] a = { 5, 10, 15, 20, 25, 30 };Now, using Group by and orderby, we will find the elements greater than 20 −var check = from element in a orderby element group element by chkGreater(element);The following is the complete code −Example Live Demousing System; using System.Linq; class Demo {    static void Main() {       int[] a = { 5, 10, 15, 20, 25, 30 };       var check = from element ... Read More

Bool Parse Method in C#

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

174 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";       bool res = bool.Parse(str);       Console.WriteLine(res);    } }OutputTrue

Advertisements