Match Any String with 'p' at the Beginning

Smita Kapse
Updated on 23-Jun-2020 08:39:10

198 Views

To match any string with p at the beginning of it with JavaScript RegExp, use the ^p Quantifier −Example           JavaScript Regular Expression                        var myStr = "Welcome to our website. We Learners!";          var reg = /^We/g;          var match = myStr.match(reg);                    document.write(match);          

Get Bounds of a Hash Three-Dimensional Array

Ankith Reddy
Updated on 23-Jun-2020 08:37:49

525 Views

To get the bounds of a three-dimensional array, use the GetUpperBound() GetLowerBound() methods in C#.The parameter to be set under these methods is the dimensions i.e.Let’s say our array is −int[, , ] arr = new int[3, 4, 5];For a three-dimensional arrays, dimension 0.arr.GetUpperBound(0) arr.GetLowerBound(0)For a three-dimensional arrays, dimension 1.arr.GetUpperBound(1) arr.GetLowerBound(1)For a three-dimensional arrays, dimension 2.arr.GetUpperBound(2) arr.GetLowerBound(2)Let us see the entire example.Example Live Demousing System; class Program {    static void Main() {       int[, , ] arr = new int[3, 4, 5];       Console.WriteLine("Dimension 0 Upper Bound: {0}", arr.GetUpperBound(0).ToString());       Console.WriteLine("Dimension 0 Lower Bound: ... Read More

Get Width and Height of a Three-Dimensional Array

karthikeya Boyini
Updated on 23-Jun-2020 08:37:18

337 Views

Let’s say our three-dimensional array is −int[,,] arr = new int[3,4,5];To get the height and width i.e. the rows and columns.Array.GetLength(0) – for rows Array.GetLength(1) – for columnsExample Live Demousing System; class Program {    static void Main() {       int[,,] arr = new int[3,4,5];       Console.WriteLine(arr.GetLength(0));       Console.WriteLine(arr.GetLength(1));       Console.WriteLine(arr.GetLength(2));    } }Output3 4 5

LINQ SkipLast Method in C#

Samual Sam
Updated on 23-Jun-2020 08:36:50

2K+ Views

Skip elements from the end and return the remaining elements using the SkipLast() method.The following is an array.int[] marks = { 45, 88, 50, 90, 95, 85 };Now, let us skip two elements from the end using SkipLast() and Lambda Expressions, but this is done after arranging the elements in descending order.IEnumerable selMarks = marks.AsQueryable().OrderByDescending(s => s).SkipLast(2);Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo {    public static void Main() {       int[] marks = { 45, 88, 50, 90, 95, 85 };       IEnumerable selMarks = marks.AsQueryable().OrderByDescending(s => s).SkipLast(2);       Console.WriteLine("Skipped ... Read More

C# Queryable SkipWhile Method

Arjun Thakur
Updated on 23-Jun-2020 08:36:30

167 Views

Bypass elements in an array and return the remaining elements using the SkipWhile() method.The following is our array −int[] marks = { 45, 88, 55, 90, 95, 85 };Now, let’s skip the elements greater than or equal to 60. The condition we have set using Lambda Expression.IEnumerable selMarks = marks.AsQueryable().OrderByDescending(s => s).SkipWhile(s => s >= 60);Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo {    public static void Main() {       int[] marks = { 45, 88, 55, 90, 95, 85 };       // skips elements above 60       IEnumerable selMarks = ... Read More

C# Enum TryParse Method

karthikeya Boyini
Updated on 23-Jun-2020 08:36:02

10K+ Views

The TryParse() method converts the string representation of one or more enumerated constants to an equivalent enumerated object.Firstly, set an enum.enum Vehicle { Bus = 2, Truck = 4, Car = 10 };Now, let us declare a string array and set some values.string[] VehicleList = { "2", "3", "4", "bus", "Truck", "CAR" };Now parse the values accordingly using Enum TryParse() method.Example Live Demousing System; public class Demo {    enum Vehicle { Bus = 2, Truck = 4, Car = 10 };    public static void Main() {       string[] VehicleList = { "2", "3", "4", "bus", "Truck", "CAR" ... Read More

C# Program to Return the Difference Between Two Sequences

Ankith Reddy
Updated on 23-Jun-2020 08:34:54

269 Views

Set two sequences.double[] arr1 = { 10.2, 15.6, 23.3, 30.5, 50.2 }; double[] arr2 = { 15.6, 30.5, 50.2 };To get the difference between both the above arrays, use Except() method.IEnumerable res = arr1.AsQueryable().Except(arr2);The following is the complete code.Example Live Demousing System; using System.Linq; using System.Collections.Generic; class Demo {    static void Main() {       double[] arr1 = { 10.2, 15.6, 23.3, 30.5, 50.2 };       double[] arr2 = { 15.6, 30.5, 50.2 };       Console.WriteLine("Initial List...");       foreach(double ele in arr1) {          Console.WriteLine(ele);       }       IEnumerable res = arr1.AsQueryable().Except(arr2);       Console.WriteLine("New List...");       foreach (double a in res) {          Console.WriteLine(a);       }    } }OutputInitial List... 10.2 15.6 23.3 30.5 50.2 New List... 10.2 23.3

Match Any String Containing Zero or More 'p's

Abhinaya
Updated on 23-Jun-2020 08:33:40

202 Views

To match any string containing zero or more p’s with JavaScript RegExp, use the p* Quantifier.ExampleYou can try to run the following code to match any string containing zero or more p’s. Here, p is considered as a number of occurrences −           JavaScript Regular Expression                        var myStr = "Welcome! Wweeeelcome to our website!";          var reg = /el*/g;          var match = myStr.match(reg);          document.write(match);          

Match Any String Containing a Sequence of N P's

Sai Nath
Updated on 23-Jun-2020 08:33:12

179 Views

To match any string containing a sequence of N p’s with JavaScript RegExp, use the p{N} Quantifier.ExampleYou can try to run the following code to match any string containing a sequence of N p’s −           JavaScript Regular Expression                        var myStr = "Welcome 1, 100, 10000, 1000";          var reg = /\d{3}/g;          var match = myStr.match(reg);                    document.write(match);          

C# LINQ Sum Method

Samual Sam
Updated on 23-Jun-2020 08:32:57

11K+ Views

Find the sum of elements using the Linq Sum() method.Here’s our list with integer elements.List list = new List { 99, 34, 77, 75, 87, 35, 88};Now find the sum using the Sum() method.list.AsQueryable().Sum();The following is an example to find the sum of elements of a list with integer elements.Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo {    public static void Main() {       List list = new List { 99, 34, 77, 75, 87, 35, 88};       int res = list.AsQueryable().Sum();       Console.WriteLine("Sum = {0}", res);    } }OutputSum = 495

Advertisements