To match any string with p at the end of it with JavaScript RegExp, use the p$ Quantifier.Example JavaScript Regular Expression var myStr = "Welcome to our website! Welcome"; var reg = /me$/g; var match = myStr.match(reg); document.write(match);
Use the LastorDefault() method to return the last element of a sequence or a default value if element isn’t there.The following is our empty list.List val = new List { };Now the following will not be able to display the last element since the list is empty. Therefore, the default would get display and error won’t be shown.val.AsQueryable().LastOrDefault();The following is the code.Example Live Demousing System; using System.Collections.Generic; using System.Linq; class Demo { static void Main() { List val = new List { }; double d = val.AsQueryable().LastOrDefault(); Console.WriteLine("Default Value = "+d); ... Read More
Merge sequences using predicate with Zip method.Here are our arrays to be merged.int[] intArray = { 10, 20, 30, 40 }; string[] stringArray = { "Jack", "Tim", "Henry", "Tom" };Now let’s use the Zip method to merge both the arrays.intArray.AsQueryable().Zip(stringArray, (one, two) => one + " " + two)The following is our code.Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { int[] intArray = { 10, 20, 30, 40 }; string[] stringArray = { "Jack", "Tim", "Henry", "Tom" }; var mergedSeq = intArray.AsQueryable().Zip(stringArray, (one, two) => one + " " + two); foreach (var ele in mergedSeq) Console.WriteLine(ele); } }Output10 Jack 20 Tim 30 Henry 40 Tom
To get the rank of a three-dimensional array, use the Rank property.Set a three-dimensional array.int[,,] arr = new int[3,4,5]Now get the rank.arr.RankLet us see the complete code.Exampleusing System; class Program { static void Main() { int[,,] arr = new int[3,4,5] Console.WriteLine("Dimensions of Array : " + arr.Rank); } }
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);
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
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
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
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
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
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP