To get a JavaScript stack trace, simply add the following in your code. It will display the stack trace −Example Live Demo function stackTrace() { var err = new Error(); return err.stack; } console.log(stackTrace()); document.write(stackTrace()); Stacktrace prints above. Output
You cannot skip a character in a capture group. A match is always consecutive, even when it contains things like zero-width assertions.ExampleHowever, you can access the matched groups in a regular expression like the following code − var str = "Username akdg_amit"; var myReg = /(?:^|\s)akdg_(.*?)(?:\s|$)/g; var res = myReg.exec(str); document.write(res[1]);
You cannot do this with JavaScript since it takes the system time which displays the current date with Date object. However, you can change the current date by changing the timezone as in the following code −Example Live Demo var date, offset, nd; date = new Date(); document.write("Current: "+date); utc = date.getTime() + (date.getTimezoneOffset() * 60000); // Singapore is GMT+8 offset = 8; nd = new Date(utc + (3600000*offset)); document.write("Singapore Time: "+nd.toLocaleString()); Output
Firstly, set two lists.List val1 = new List { 25, 30, 40, 60, 80, 95, 110 }; List val2 = new List { 27, 35, 40, 75, 95, 100, 110 };Now, use the Intersect() method to get the intersection between two lists.IEnumerable res = val1.AsQueryable().Intersect(val2);Example Live Demousing System; using System.Collections.Generic; using System.Linq; class Demo { static void Main() { List val1 = new List { 25, 30, 40, 60, 80, 95, 110 }; List val2 = new List { 27, 35, 40, 75, 95, 100, 110 }; IEnumerable res = val1.AsQueryable().Intersect(val2); Console.WriteLine("Intersection of both the lists..."); foreach (int a in res) { Console.WriteLine(a); } } }OutputIntersection of both the lists... 40 95 110
The shell is the command interpreter on the Linux systems. It the program that interacts with the users in the terminal emulation window. Shell commands are instructions that instruct the system to do some action.Some of the commonly used shell commands are −basenameThis command strips the directory and suffix from filenames. It prints the name of the file with all the leading directory components removed. It also removes a trailing suffix if it is specified.Example of basename is as follows −$ basename country/city.txtThis gets the name of the file i.e. city which is present in folder country.city.txtcatThis command concatenates and ... Read More
Convert a specified value to a 16-bit signed integer using the Convert.ToInt16 method in C#.We have a double variable with a value initialized to it.double doubleNum = 3.456;Now, let us convert it to Int16 i.e. short.short shortNum; shortNum = Convert.ToInt16(doubleNum);Here is the complete example −Example Live Demousing System; public class Demo { public static void Main() { double doubleNum = 3.456; short shortNum; shortNum = Convert.ToInt16(doubleNum); Console.WriteLine("Converted {0} to {1}", doubleNum, shortNum); } }OutputConverted 3.456 to 3
Use the Convert.ToUInt16 method to convert a specified value to a 16-bit unsigned integer.Here is our string −string str = "1129";Now let us convert it to 16-bit unsigned integer.ushort res; res = Convert.ToUInt16(str);The following is the complete example −Example Live Demousing System; public class Demo { public static void Main() { string str = "1307"; ushort res; res = Convert.ToUInt16(str); Console.WriteLine("Converted string '{0}' to {1}", str, res); } }OutputConverted string '1307' to 1307
Enumerable.Repeat method is part of System.Linq namespace.It returns a collection with repeated elements in C#.Firstly, set which element you want to repeat and how many times.As an example, let us see how to repeat number 10, five times −Enumerable.Repeat(10, 5);The following is the complete example −Example Live Demousing System; using System.Linq; class Demo { static void Main() { var val = Enumerable.Repeat(10, 5); foreach (int res in val) { Console.WriteLine(res); } } }Output10 10 10 10 10
The Aggregate() method applies an accumulator function over a sequence.The following is our array −string[] arr = { "DemoOne", "DemoTwo", "DemoThree", "DemoFour"};Now use the Aggregate() method. We have set the ssed value as “DemoFive” for comparison.string res = arr.AsQueryable().Aggregate("DemoFive", (longest, next) => next.Length > longest.Length ? next : longest, str => str.ToLower());Here, the resultant string should have more number of characters than the initial seed value i.e. “DemoFive”.Example Live Demousing System; using System.Linq; class Demo { static void Main() { string[] arr = { "DemoOne", "DemoTwo", "DemoThree", "DemoFour"}; string res = arr.AsQueryable().Aggregate("DemoFive", (longest, next) ... Read More
To represent Int64 as a Binary string in C#, use the ToString() method and set the base as the ToString() method’s second parameter i.e. 2 for Binary.Int64 represents a 64-bit signed integer.Firstly, set an Int64 variable.long val = 753458;Now, convert it to binary string by including 2 as the second parameter.Convert.ToString(val, 2)Example Live Demousing System; class Demo { static void Main() { long val = 753458; Console.WriteLine("Long: "+val); Console.Write("Binary String: "+Convert.ToString(val, 2)); } }OutputLong: 753458 Binary String: 10110111111100110010
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP