zoukankan      html  css  js  c++  java
  • 命令行查单词

    需求来源

    这两天做一个拍卖网站的项目,偶尔会有一些单词想不起来,顺手花五分钟就写了一个查单词的,命令行简单点就它了。

    源码

    class result
        {
            //{"from":"en","to":"zh","trans_result":[{"src":"find","dst":"u627eu5230"}]}
            public string from { get; set; }
            public string to { get; set; }
            public trans_result[] trans_result { get; set; }
        }
    
        class trans_result
        {
            public string src { get; set; }
            public string dst { get; set; }
        }
        class Program
        {
            private static String DecodeUnicode(String dataStr)
            {
                Regex reg = new Regex(@"(?i)\[uU]([0-9a-f]{4})");
                return reg.Replace(dataStr, delegate(Match m) { return ((char)Convert.ToInt32(m.Groups[1].Value, 16)).ToString(); });
    
    
            }
            static void Main(string[] args)
            {
                if (args.Length>0)
                {
                    string s1 = args[0].ToString();
                    string url = string.Format("http://openapi.baidu.com/public/2.0/bmt/translate?client_id={0}&q={1}&from={2}&to={3}", "这里填写百度appid", s1, "auto", "auto"); 
                    WebClient wc = new WebClient();
                    result r = JsonConvert.DeserializeObject<result>(wc.DownloadString(url));
                    Console.WriteLine(DecodeUnicode(r.trans_result[0].dst));
                    Console.WriteLine("......");
                }
                else
                {
                    while (true)
                    {
    
                        string s = Console.ReadLine();
                        if (s == "over" || s == "quit" || s == "exit")
                        {
                            break;
                        }
                        string url = string.Format("http://openapi.baidu.com/public/2.0/bmt/translate?client_id={0}&q={1}&from={2}&to={3}", "这里填写百度appid", s, "auto", "auto"); 
                WebClient wc
    = new WebClient();
                result r
    = JsonConvert.DeserializeObject<result>(wc.DownloadString(url));
                Console.WriteLine(DecodeUnicode(r.trans_result[
    0].dst)); Console.WriteLine("......"); } }
                Console.WriteLine(
    "退出查单词,感谢使用!");
              }
            }

    没什么技术难度,方便生活而已,最后想在命令行直接调用,别忘配置path环境变量,大约就是酱

  • 相关阅读:
    [译]Chapter 3 Understanding Controllers
    Effiective C# Item1 : 使用属性代替成员变量
    终于出版了
    《Thinking in UML》读书笔记之一
    【译】ClickOnce部署概述
    [译]Chapter 2 Building a Simple ASP.NET MVC Application
    开始翻译《Application Architecture Guide 2.0》
    [译]Chapter 1 An Introduction to ASP.NET MVC(1)
    [译]Chapter 1 An Introduction to ASP.NET MVC(3)
    Effective C# Item4:使用Conditional特性代替#if条件编译
  • 原文地址:https://www.cnblogs.com/yeanzhi/p/3667538.html
Copyright © 2011-2022 走看看