如何替换包含“,"的csv字符串带有"^"使用System.Text.RegularExpressions.Regex.Replace [英] how to replace a csv string which contains "," with "^" using System.Text.RegularExpressions.Regex.Replace

查看:97
本文介绍了如何替换包含“,"的csv字符串带有"^"使用System.Text.RegularExpressions.Regex.Replace的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用System.Text.RegularExpressions.Regex.Replace将包含,"的csv字符串替换为"^"
这是因为我的数据还包含分隔的值,这在拆分

how to replace a csv string which contains "," with "^" using System.Text.RegularExpressions.Regex.Replace
this is becuase since my data also contains ,separted values which makes problem while splitting

推荐答案

时可能会造成问题.

如果您的数据包含,"字符,并且分隔符也是,",则正则表达式无法比CSV文件读取器识别更多-出于相同的原因.
唯一可能的是,如果您的数据在CSV中以某种方式进行了格式化:如果可以检测到样式或位置,则有可能识别流氓",,"字符.

您是否有少量但相关的数据样本,可能会显示出这种模式?

另一种解决方案是不要使用,"作为CSV分隔符!
You probably can''t.

If your data contains '','' characters, and you separation character is also '','' then a Regex can no more identify it than the CSV file reader can - for the same reason.

The only possiblity is if your data is formatted in some way within the CSV: it may be possible to identify "rogue" '','' characters if there is a detectable pattern or placement.

Do you have a small-but-relevent sample of your data that might show such a pattern?

The other solution is to not use a '','' as your CSV separator!


这篇关于如何替换包含“,"的csv字符串带有"^"使用System.Text.RegularExpressions.Regex.Replace的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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