Return to Snippet

Revision: 6283
at May 14, 2008 07:18 by AndrewVos


Initial Code
/// <summary>
		/// Class to launch Google Search in default browser.
		/// </summary>
		public static class Google {
			/// <summary>
			/// Launches Google Search in default browser, and escapes string according to: http://code.google.com/apis/searchappliance/documentation/46/xml_reference.html#appendix_url_escaping
			/// </summary>
			/// <param name="searchQuery">The search query.</param>
			public static void SearchGoogle(string searchQuery) {
				string fixedSearchQuery = null;

				foreach (char character in searchQuery) {
					if (Char.IsLetterOrDigit(character)) {
						fixedSearchQuery += character;
					} else if (character == Char.Parse(" ")) {
						fixedSearchQuery += "+";
					} else {
						fixedSearchQuery += Uri.HexEscape(character);
					}
				}

				string url = @"http://www.google.com/search?hl=en&q=" + fixedSearchQuery;

				try {
					Process.Start(url);
				} catch { }
			}
		}

Initial URL

                                

Initial Description
Properly escapes the query string, according to http://code.google.com/apis/searchappliance/documentation/46/xml_reference.html#appendix_url_escaping

Initial Title
Launch Google Search in default Browser

Initial Tags
search, google, query

Initial Language
C#