用扭曲替换C#.net中的String [英] Replace String in C#.net with a twist

查看:106
本文介绍了用扭曲替换C#.net中的String的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我想从字符串中删除单词-这是一个示例

String ="a男孩有一个名为a"的魔术棒"
结果=一个男孩有个魔杖,名字叫""

在上面的示例中,字母``a''不在单词中时被删除(即后跟非空白或以非空白开头或在句子开头或句子结尾处)

有快速的方法吗?

谢谢.

EK

Hi I want to remove words form a string - Here is an example

String="a boy has a magic wand named a a"
Result="a boy has magic wand named a"

in the above example, the letter ''a'' was removed when it is not part of a word(i.e. followed by non-blank or preceded by non-blank or at sentence beginning or at sentence end)

is there a quick way to do this?

Thanks.

EK

推荐答案

只需执行搜索并替换为"a".然后检查句子的开头或结尾是否是单词"a",并在需要时将其替换.您还需要三个正则表达式来执行此操作,所以我能想到的没有比这更快的方法了.
Just do a search and replace for " a ". Then check if the start or end of the sentence is the word ''a'' and replace that if need be. You need three regex to do it, too, so there''s no quicker way than that, that I can think of.


感谢大家的帮助.
为了向优素福澄清,我将一个单词定义为一个字符串,在字符串的两边都有一个空白.
如果两边都不为空白,则不是一个字.
以威斯康星州的罪孽"一词为例.第二个罪是一个单词",温斯康辛州的最后一个字符串不是一个单词.

再次感谢您的帮助,正如Christian所说的那样,必须进行3个函数调用.

EK
Thank you all for your help.
To clarify to Yusuf, I define a word as a string with a blank on both sides.
If either sides is not blank it is not a word.
Take for example the word case of "Sin Sin in Wisconsin". The 2nd Sin is a ''word'' the last string in Winsconsin is not a word.

Thanks again for your help, as Christian said 3 function calls are necessary.

EK


这篇关于用扭曲替换C#.net中的String的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆