C#转引自删除的字符串分隔符 [英] C# Removing separator characters from quoted strings

查看:131
本文介绍了C#转引自删除的字符串分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写必须从引用的字符串在文本文件中删除分隔符的节目



例如:

 你好,我的名字是世界上

动作:

 你好,我的名字是世界上

这听起来起初很简单(我认为这将是),但你需要的时候报价开始,当报价结束,然后搜索特定字符串检测分隔符。怎么样?



我已经尝试了一些Regexs但我只是不断收到自己糊涂了!



任何想法?即使只是一些让球滚动,我只是完全难住了。


解决方案

 字符串模式=\([^ \] +)\; 
值= Regex.Match(textToSearch,图案).value的;

的String [] removalCharacters = {,,,}; //或任何其他字符
的foreach(在removalCharacters串字符)
{
值为= value.Replace(字符,);
}


I'm writing a program that has to remove separator characters from quoted strings in text files.

For example:

"Hello, my name is world"

Has to be:

"Hello my name is world"

This sounds quite easy at first (I thought it would be), but you need to detect when the quote starts, when the quote ends, then search that specific string for separator characters. How?

I've experimented with some Regexs but I just keep getting myself confused!

Any ideas? Even just something to get the ball rolling, I'm just completely stumped.

解决方案

string pattern = "\"([^\"]+)\"";
value = Regex.Match(textToSearch, pattern).Value;

string[] removalCharacters = {",",";"}; //or any other characters
foreach (string character in removalCharacters)
{
    value = value.Replace(character, "");
}

这篇关于C#转引自删除的字符串分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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