Get Stack Trace for JavaScript Exception

Srinivas Gorla
Updated on 23-Jun-2020 05:12:18

498 Views

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

Skip Character in Capture Group in JavaScript Regexp

Rishi Rathor
Updated on 23-Jun-2020 05:07:57

961 Views

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]);                      

Set Current Time to Another Time in JavaScript

Daniol Thomas
Updated on 23-Jun-2020 05:05:53

586 Views

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

Intersect Two Lists in C#

George John
Updated on 22-Jun-2020 15:51:21

10K+ Views

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

What Are Shell Commands

Kristi Castro
Updated on 22-Jun-2020 15:49:49

12K+ Views

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 toInt16 Method in C#

Chandu yadav
Updated on 22-Jun-2020 15:46:02

833 Views

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

Convert to UInt16 Method in C#

Arjun Thakur
Updated on 22-Jun-2020 15:45:35

275 Views

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 in C#

Ankith Reddy
Updated on 22-Jun-2020 15:45:10

3K+ Views

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

Chash Aggregate Method

George John
Updated on 22-Jun-2020 15:44:36

620 Views

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

Represent int64 as a Binary String in C#

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

2K+ Views

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

Advertisements