Skip to content

Instantly share code, notes, and snippets.

@EsProgram
Created June 3, 2014 15:40
Show Gist options
  • Save EsProgram/c424d05a58bb6c9f5f7d to your computer and use it in GitHub Desktop.
Save EsProgram/c424d05a58bb6c9f5f7d to your computer and use it in GitHub Desktop.
TestではBrowserSeaechを読み込んでテストしています
using System;
using System.Text;
using System.Web;
namespace Es.Web
{
class BrowserSeaech
{
/// <summary>
/// 検索サイトの指定
/// </summary>
public enum SearchSite
{
Google,
Yahoo,
}
readonly String url;
/// <summary>
/// 検索サイトを決定することで
/// 自動的に既定のパラメータを指定する(エンコード方法等)
/// </summary>
/// <param name="site">検索エンジン</param>
public BrowserSeaech(SearchSite site)
{
switch(site)
{
case SearchSite.Google:
url = @"http://www.google.co.jp/search?hl=ja&ie=utf-8&oe=utf-8&q=";
break;
case SearchSite.Yahoo:
url = @"http://search.yahoo.co.jp/search?fr=yssn&ei=utf-8&q=";
break;
default:
url = String.Empty;
break;
}
}
/// <summary>
/// keywordに指定した文字列に対して検索をかける
/// </summary>
/// <param name="keyword">検索文字列</param>
/// <returns></returns>
public String GetSearchUrl(String keyword)
{
return String.Format("{0}{1}",
url,
HttpUtility.UrlEncode(keyword, Encoding.UTF8));
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Es.Web;
using Es.FormApplication;
using System.Diagnostics;
namespace CSharpConsole
{
sealed class テスト
{
static void Main(string[] args)
{
BrowserSeaech b = new BrowserSeaech(BrowserSeaech.SearchSite.Google);
String str = b.GetSearchUrl("これについて調べて");
Process.Start(str);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment