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/>");
}

转载于:https://www.cnblogs.com/Yellowshorts/archive/2013/01/19/2867549.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值