This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TestではBrowserSeaechを読み込んでテストしています |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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