Entries:
Comments:
Posts:

Loading User Information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading User Information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

x.static

x.static x.static

Niner since 2004

  • Learn how 10 was made

    Perhaps I'm just hearing things, but I'm pretty sure Scoble used a 4 letter word at ~21:01 Wink.

    Great video, and I can't wait to see some of the code behind this.
  • Robert Fripp - Behind the scenes at Windows Vista recording session

    thrang wrote:
    Fripp is a big-time Macintosh user....


    I'm sure his computer preferences didn't get in the way of god only knows how much MS paid him for a day's worth of work.
  • Gary Daniels and Evan Goldring - Mock whiteboard problem

    eeesh, it ate my for loop...

    static private bool isPalindrome (string stringToTest)

    {

    char[] stringChars = stringToTest.ToCharArray();

    // format the string

    foreach (char character in stringChars)

    {

    if (char.IsPunctuation(character) || char.IsSeparator(character))

    {

    stringToTest = stringToTest.Replace(character.ToString(), "").ToLower();

    }

    }

    int halfwayMark = (stringToTest.Length/2);

    char[] firstHalf = stringToTest.Substring(0, halfwayMark).ToCharArray();

    char[] secondHalf = stringToTest.Substring(halfwayMark).ToCharArray();

    Array.Reverse(secondHalf);

    for (int i=0;i<halfwayMark;i++)

    {

    if (firstHalf[i] != secondHalf[i])

    {

    return false;

    }

    }

    return true;

    }

  • Gary Daniels and Evan Goldring - Mock whiteboard problem

    refactored my earlier code:

    static private bool isPalindrome (string stringToTest)
    {
     char[] stringChars = stringToTest.ToCharArray();
     
    // format the string
     foreach (char character in stringChars)
     {
       if (char.IsPunctuation(character) || char.IsSeparator(character))
       {
         stringToTest = stringToTest.Replace(character.ToString(), "").ToLower();
       }
     }

     int halfwayMark = (stringToTest.Length/2);
     char[] firstHalf = stringToTest.Substring(0, halfwayMark).ToCharArray();
     char[] secondHalf = stringToTest.Substring(halfwayMark).ToCharArray();

     Array.Reverse(secondHalf);

     for (int i=0;i

     {
        if (firstHalf[i] != secondHalf[i])
       {
         return false;
       }
     }
     return true;
    }

    performance wise, this is much cheaper than most other solutions presented as it goes char by char.

  • Gary Daniels and Evan Goldring - Mock whiteboard problem

    static private bool isPalindrome (string stringToTest)

    {

    char[] stringChars = stringToTest.ToCharArray();

    foreach (char character in stringChars)

    {

    if (char.IsPunctuation(character) || char.IsSeparator(character))

    {

    stringToTest = stringToTest.Replace(character.ToString(), "").ToLower();

    }

    }

    if (stringToTest.Length % 2 == 0) // even number of characters in the string

    {

    int halfwayMark = (stringToTest.Length/2);

    char[] firstHalf = stringToTest.Substring(0, halfwayMark).ToCharArray();

    char[] secondHalf = stringToTest.Substring(halfwayMark, stringToTest.Length-halfwayMark).ToCharArray();

    bool flag = true; // innocent until proven guilty

    Array.Reverse(secondHalf);

    for (int i=0;i<halfwayMark;i++)

    {

    if (firstHalf[i] != secondHalf[i])

    {

    flag = false;

    break; // break out of the loop

    }

    }

    return flag;

    }

    else // odd number of chars, middle char needs to be ignored

    {

    int halfwayMark = (stringToTest.Length/2) + 1;

    char[] firstHalf = stringToTest.Substring(0, halfwayMark).ToCharArray();

    char[] secondHalf = stringToTest.Substring(--halfwayMark).ToCharArray();

    bool flag = true;

    Array.Reverse(secondHalf);

    for (int i=0;i<halfwayMark;i++)

    {

    if (firstHalf[i] != secondHalf[i])

    {

    flag = false;

    break; // break out of the loop

    }

    }

    return flag;

    }

    }