Wednesday, July 29, 2020

Extract desired word from string using regex in c#



string s = "1234 hyy dsad sfsf foorer dfdfdsf dvdvds";

            Regex regex = new Regex(@"\d+");
            var data = regex.Match(s);


output :1234

Saturday, July 25, 2020

Difference : Object, Var and Dynamic type


  public int Add(int a, int b)
        {
            object i = 100;

            i = i + 200;  // not allow arithmetic operations


            var s = 100;

            s = s + 100; // No error compile type checking

            dynamic ss = 100;

            ss = ss + 200;
            Console.WriteLine(ss);

            ss = "Hi"; // No error runtime type checking

        }

Difference : for and foreach




For:
 for(int i=0; i<1000; i++){
}
The for loop executes a statement or a block of statements repeatedly until a specified expression evaluates to false.
There is a need to specify the loop bounds (minimum or maximum).
 Following is a code example of a simple for loop that starts 0 till <= 5.
foreach :
          foreach (var item in collection)
            {
              //  slow compare to for loop .
            // not allow to item modifications 
            }
we look at foreach in detail. 
What looks like a simple loop on the outside is actually a complex data structure called an enumerator:
An enumerator is a data structure with a Current property, a MoveNext method, and a Reset method. The Current property holds the value of the current element, and every call to MoveNext advances the enumerator to the next item in the sequence.
Enumerators are great because they can handle any iterative data structure. In fact, they are so powerful that all of LINQ is built on top of enumerators.
But the disadvantage of enumerators is that they require calls to Current and MoveNext for every element in the sequence. All those method calls add up, especially in mission-critical code.


Friday, July 17, 2020

ChromeOptions :



  • start-maximized: Opens Chrome in maximize mode
  • incognito: Opens Chrome in incognito mode
  • headless: Opens Chrome in headless mode
  • disable-extensions: Disables existing extensions on Chrome browser
  • disable-popup-blocking: Disables pop-ups displayed on Chrome browser
  • make-default-browser: Makes Chrome default browser
  • version: Prints chrome browser version
  • disable-infobars: Prevents Chrome from displaying the notification 'Chrome is being controlled by automated software
ChromeOptions options = new ChromeOptions()
options.addArgument("start-maximized");
ChromeDriver driver = new ChromeDriver(options);
https://www.guru99.com/chrome-options-desiredcapabilities.html

Tuesday, July 14, 2020

Local Q's: Reverse a String without using any loop or inbuilt methods?



  1. String reverse(String s)
  2. {
  3. if(s.length() == 0)
  4. return "";
  5. return s.charAt(s.length() - 1) + reverse(s.substring(0,s.length()-1));
  6. }