用单引号替换逗号但忽略逗号分隔的字符串 [英] Replace commas in single quotes but ignore comma separated string

查看:93
本文介绍了用单引号替换逗号但忽略逗号分隔的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我想使用正则表达式替换带空格的单引号中的逗号,但忽略逗号分隔的字符串。


<有没有人知道怎么做C#?





示例:


原始字符串:


" abc,'this,demo',foo,'hello,world',bar ,,"


更换引号中的逗号后,结果为:


" abc,'this demo',foo ,'hello world',bar ,,"

解决方案

选中:

 var example =" abc,'this,demo',foo,'hello,world',bar ,," ;; 
var result = Regex.Replace(例如,@",(?= [^'] *'([^'] *'[^'] *')* [^'] *


)","");

Console.WriteLine(示例);
Console.WriteLine(结果);




Hello,

I would like to use regular expression to replace commas in single quotes with spaces, but ignore comma separated string.

Does anyone know how to do in C#?


Example:

Original string:

"abc,'this,demo',foo,'hello,world', bar, ,"

After replacing the commas in quotes, the result is:

"abc,'this demo',foo,'hello world', bar, ,"

解决方案

Check this:

var example = "abc,'this,demo',foo,'hello,world', bar, ,";
var result = Regex.Replace( example, @",(?=[^']*'([^']*'[^']*')*[^']*


)", " " ); Console.WriteLine( example ); Console.WriteLine( result );



这篇关于用单引号替换逗号但忽略逗号分隔的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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