zoukankan      html  css  js  c++  java
  • LInq 中使用正则表达试

    //给字符串变量赋值
    string text = @"A better activation model is to allocate an object for a client only while a call is in progress from the client to the service.
    That way, you have to create and maintain only as many objects in memory as there are concurrent calls,
    not as many objects as there are outstanding clients. Between calls,
    the client holds a reference on a proxy that doesn't have an actual object at the end of the wire.
    The obvious benefit is that you can now dispose of the expensive resources the service instance occupies long before the client disposes of the proxy.
    By that same token, acquiring the resources is postponed until they are actually needed by a client.
    The second benefit is that forcing the service instance to reallocate or connect to its resources on every call caters very well to
    transactional resources and transactional programming because it eases the task of enforcing consistency with the instance state.";
    //创建匹配以ing结尾单词的正则表达式
    Regex r = new Regex(@"ing\b");
    //按单词转换为字符串数组
    string[] words = text.Split(new char[] { '.', '?', '!', ' ', ';', ':', ',' },
                             StringSplitOptions.RemoveEmptyEntries);
    //LINQ查询以ing结尾的单词
    var query = from item in words
                     where r.Match(item).Success == true
                      select item;

    //显示查询结果
    foreach (var item in query)
    {
    Response.Write(item.ToString() + "<br/>");
    }

  • 相关阅读:
    【翻译自mos文章】rman 标准版和企业版的兼容性
    HDU 1010 Tempter of the Bone
    uva 10716 Evil Straw Warts Live(贪心回文串)
    适配器及适配器模式
    Android推送技术研究
    【hadoop2.6.0】倒排索引遇到问题了
    【hadoop2.6.0】MapReduce原理
    【hadoop2.6.0】一句话形容mapreduce
    【leetcode】Median of Two Sorted Arrays(hard)★!!
    【leetcode】Merge k Sorted Lists
  • 原文地址:https://www.cnblogs.com/Yellowshorts/p/2867549.html
Copyright © 2011-2022 走看看