11 Cool Visual Studio tricks

Programming No Comments »

Over at Stephen Walther's ASP.NET blog he shares 11 useful tips/tricks that you can use in Visual Studio.  Several seem to be strictly VS2008, but I did manage to get some of them to work in VS2005... my favorite being automatically generating a property by typing "prop" and hitting "tab" twice.  Wow!  What a time saver!

Check it out... :)

Open Chrome in “Incognito”

JavaScript No Comments »

Since Chrome has arrived I have been looking for a means to open directly into the "Ingonito" window.  Finally, someone has a script to do so.  Go to the following URL, copy and paste the script into notepad (naming it .js) saving it to a directory easy to get to (like your desktop).  All you have to do is double click and you're all set!

I came across this on Lifehacker. The script can be found at Michael T. Bee's ESI.

Updated Instructions

You need to put this JavaScript file into the directory containing chrome.exe such as:

C:\Documents and Settings\<windows user>\Local Settings\Application Data\Google\Chrome\Application\

Create a shortcut to the script if you wish to run it from the desktop or another directory.  If you don't do this you will most likely get a "file not found" error because the script cannot locate Chrome.

C# search string forward and backwards

C#, Programming No Comments »

I ran into a requirement working on a piece of code that needed me to search a string from beginning to end and then from end to the beginning.  This is the solution that I came up with consists of three methods.  One method to simulate the InStr function from the old vb days, one to reverse a string and another to do the actual matching:

	public bool ForwardBackwardMatch(string stringSearched,
		string searchCriteria)
	{
		bool matchFound = false;
		if (stringSearched.Trim() != string.Empty)
		{
			// search criteria in string?
			if (InStr(stringSearched, searchCriteria))
			{
				matchFound = true;
			}

			// reverse our string
			string stringSearchedReverse =
					StringReverse(stringSearched);
			// recheck against criteria
			if (InStr(stringSearchedReverse, searchCriteria))
			{
				matchFound = true;
			}
		}
		return matchFound;
	}

	public bool InStr(string stringSearched, string searchCriteria)
	{
		bool returnVal;
		if (stringSearched.IndexOf(searchCriteria.Trim()) == -1)
		{
			returnVal = false;
		}
		else
		{
			returnVal = true;
		}
		return returnVal;
	}

	public string StringReverse(string s)
	{
		char[] charArray = s.ToCharArray();
		for (int i = 0, j = charArray.Length - 1;
			i < j; i++, j--)
		{
			charArray[j] = s[i];
			charArray[i] = s[j];
		}
		return new String(charArray);
	}

Removing Odd Characters from Strings.

Programming No Comments »

Okay, so I ran into an issue while working on a project at work where an internal web service was returning a large string of text as driving directions that apparently was copied and pasted out of a word document.  The problem was that unicode characters (tiny rectangle representing a list item bullet for example) were strung all throughout the text.  Just imagine a blurb of text that is about 2000 characters but there isn't a single bit of formatting in it.  So I set out to find some code since I knew that someone had to have had this problem at some point or another.  I ran into the following, which ended up being exactly what I was looking for:

The blog post entitled "A .NET Unicode Puzzle (Revised)" had the answers I sought.  Below is an example of the method that I ended up using in my solution.

public static string RemoveUnicode(string s)
{
    try
    {
	string normalized = s.Normalize(NormalizationForm.FormKD);
	Encoding ascii = Encoding.GetEncoding(
	      "us-ascii",
	      new EncoderReplacementFallback(string.Empty),
	      new DecoderReplacementFallback(string.Empty));
	byte[] encodedBytes = new byte[ascii.GetByteCount(normalized)];
	int numberOfEncodedBytes = ascii.GetBytes(normalized, 0,
        normalized.Length, encodedBytes, 0);
	string newString = ascii.GetString(encodedBytes);
	return newString;
    }
    catch
    {
	return s;
    }
}

Ajax Error: Sys.ArgumentOutOfRangeException

Programming No Comments »

So, after working on a piece of code at work for over a month and migrating it to QA I had an error that I couldn't quite figure out that only appeared while viewing the site in FireFox.  The error is "Sys.ArgumentOutOfRangeException" and mentions that an integer is expected but was NaN.  Okay.  That's helpful considering its a JavaScript error and IE's JS debugging is entirely junk.  Want to know the trick?  The frameset contained a value for frameborder='yes' inside of it.  Apparently the script, in IE, requires an integer value to be used instead of the yes/no value.  All I did was change it to a 0 from a 'no' and the page started working fine.

Annoying

Design by j david macor.com.Original WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in