加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 对单词和排队标点符号进行字符串拆分

发布时间:2020-12-16 01:58:54 所属栏目:百科 来源:网络整理
导读:这是我现在使用的模式: string pattern = @"^(s+|d+|w+|[^dsw])+$";Regex regex = new Regex(pattern);if (regex.IsMatch(inputString)){ Match match = regex.Match(inputString); foreach (Capture capture in match.Groups[1].Captures) { if (!st
这是我现在使用的模式:

string pattern = @"^(s+|d+|w+|[^dsw])+$";

Regex regex = new Regex(pattern);
if (regex.IsMatch(inputString))
{
      Match match = regex.Match(inputString);

      foreach (Capture capture in match.Groups[1].Captures)
      {
           if (!string.IsNullOrWhiteSpace(capture.Value))
               tmpList.Add(capture.Value);
      }
 }
 return tmpList.ToArray<string>();

有了这个,我检索一个字符串数组,每个单词的项目和每个标点字符的一个项目.

我现在想要实现的是将排队的标点字符分组只在一个项目中,即现在如果一个接一个地有三个点,我在我的数组中得到三个项目,每个项目包含一个点.最终我想要一个带有三个圆点的项目(或任何其他标点符号).

解决方法

尝试使用以下模式.我加了一个额外的.如果您想要其他内容,请告诉我.希望能帮助到你.

string pattern = @"^(s+|d+|w+|[^dsw]+)+$";

对于inputString =“abc; .. cbe; aaa … kjaskjas”我得到了这个结果:

abc
;..
cbe
;
aaa
...
kjaskjas

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读