Friday, August 23, 2013

CSharp C# string to enum example

CSharp C# string to enum example


Output:

enumNow int value=1, wordvalue=fred
enumNow int value=0, wordvalue=joe



Program.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using System.IO;

class Stuff4
{
    static void Main()
    {
        ShowEnumInfoOnPassedMatchingStringToEnum("fred");
        ShowEnumInfoOnPassedMatchingStringToEnum("joe");
        Console.ReadLine();
    }

    private static void ShowEnumInfoOnPassedMatchingStringToEnum(string enumWord)
    {
        ProcessToRun enumNow = (ProcessToRun)Enum.Parse(typeof(ProcessToRun), enumWord);
        Console.WriteLine("enumNow int value={0}, wordvalue={1}", (int)enumNow, enumNow);       
    }

        public enum ProcessToRun
        {
            joe,
            fred
        }
}


CSharp C# XDocument Very Simple Read and locate with Linq

CSharp C# XDocument Very Simple Read and locate with Linq


The XML Target:

<?xml version="1.0" encoding="utf-8"?><root>
<TestEnvironment>QA_TestZoneNow</TestEnvironment>
<Browser>Chrome</Browser>
<NewCompanyNameForTrackerAdminRemoteSetup>CLK_Q2_007</NewCompanyNameForTrackerAdminRemoteSetup>
<CreateAndUseNewCompany>TRUE</CreateAndUseNewCompany>
</root>


The output:

Iterate all the elements by their name and value properties:
elementNow=TestEnvironment
  ValueNow=QA_TestZoneNow
elementNow=Browser
  ValueNow=Chrome
elementNow=NewCompanyNameForTrackerAdminRemoteSetup
  ValueNow=CLK_Q2_007
elementNow=CreateAndUseNewCompany
  ValueNow=TRUE
Find the "Browser" tag in full:
browserNow element and value together=<Browser>Chrome</Browser>
Browser tag name=Browser and tag value=Chrome


Program.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;

class Stuff4
{
    static void Main()
    {
        string targetFile = @"C:\Dump2\UnattendedTestThreadAppConfigUpdates.xml";
        XDocument fileNow = XDocument.Load(targetFile);
        IEnumerable<XElement> listOfElements = fileNow.Descendants().Elements();
        Console.WriteLine("Iterate all the elements by their name and value properties:");
        foreach (XElement elementNow in listOfElements)
        {
            Console.WriteLine("elementNow={0}", elementNow.Name);
            Console.WriteLine("  ValueNow={0}", elementNow.Value);
        }
        Console.WriteLine("Find the \"Browser\" tag in full:");
       XElement browserNow = listOfElements.First((eNow) => eNow.Name == "Browser");
       Console.WriteLine("browserNow element and value together={0}", browserNow);
       Console.WriteLine("Browser tag name={0} and tag value={1}", browserNow.Name, browserNow.Value);
        Console.ReadLine();
    }
}


Tuesday, August 20, 2013

CMD DOS how to delete erase an environmental variable

CMD DOS how to delete erase an environmental variable

set theVariable=

This will remove it from the environment variables

C:\>set aVar=fred and barney

C:\>echo %aVar%
fred and barney

C:\>set aVar=

C:\>echo %aVar%
%aVar%

C:\>


Note:  to show set variables:  set ""

Thursday, August 15, 2013

CSharp C# Regular Expression REPLACE example

CSharp C# Regular Expression REPLACE example

using System;
using System.Text.RegularExpressions;

class Stuff4
{
    static void Main()
    {
        /*
             Before:  A hiker is not a climber
            After :  A hotter is not a climber
            [replace "iker" with "otter"]

            - This example passes in the string "A hiker is not a climber",

            - Then we pass in a RegEx search pattern "(.*)(iker)(.*)" that:
                Takes any character any number of times until we find "iker" so
                it will return "A h" as the first find (a/k/a $1). 
                And "iker" will be $2.  Finally, any character, after "iker", any
                number of times, which is " is not a climber" (a/k/a $3)

            - Then we pass in a RegEx string that describes how we want the matches
                reconstructed with "$1otter$3":
                    - Start by picking up $1: "A h"
                    - Then add the arbitrary string "otter" (and skip $2 ["iker"]
                    - Finally, add $3: " is not a climber"

            - We get the reconstructed string: "A hotter is not a climber"
         *
         * ACTUAL OUTPUT:
                A hiker is not a climber
                A hotter is not a climber
         */
        string inputNow = "A hiker is not a climber";
        string outputNow = Regex.Replace(inputNow, "(.*)(iker)(.*)", "$1otter$3");       
        Console.WriteLine(inputNow);
        Console.WriteLine(outputNow);
        Console.ReadLine();
    }
}


Thursday, August 1, 2013

JavaScript – event – fire programically

JavaScript – event – fire programically


This example works on IE, Firefox, and Chrome




This example uses the mouseover - disregard the word click....


<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
    <input type=button id="btnTopButton" value="I am the top" onmouseover="alert('I am the top button.')">

    <br />
    <br />

    <input type=button id=Button1 value="Click on Top Button"
        onclick="javascript:TestFire();">

    <script>
        function TestFire() {           
            document.getElementById('btnTopButton').onmouseover();           
        }
    </script>
</body>
</html>