One sample is used to replace double quote from words which encapsulated by csvwriter ,

you know csv writer will take care of the double quote and comma and new line,

So if the words has comma or new line, csv writer will use default text qualifier double quote

Enclose them, sample :

Source : evan,yao CSV :"evan,yao"

And it will replace every double quote with two double quote.

Such as source data is evan,yao" csv: "evan,yao"""

So when we read csv words, we should replace the additional double quote,

I use c# and regex to do this, the following is two simple sample.

One is remove text qualifier, another one is replace demo.

Please enjoy.

using System;

using System.Text.RegularExpressions;

using System.IO;

using System.Collections;

public class test

{

public static string removeTextQualifier(string text)

{

string pattern = "^\"(?<word>.*)\"$";

Regex rgx = new Regex(pattern);

MatchCollection matches = rgx.Matches(text);

if(matches.Count>)

return matches[].Groups[].Value.Replace("\"\"", "\"");

else

return text;

}

public static void regexReplaceDemo(int type)

{

string words = "letter alphabetical missing lack release " +

"penchant slack acryllic laundry cease";

if(type == )

words = @"select *from table1 left join table2 on table1.col1=table2.col2

right join t3 on table1.col2=t3.col1 full join t4 on t4.c1=t3.col2 where 1=1

and 2=2 or 3=3";

Console.WriteLine("Original words:");

Console.WriteLine(words);

Console.WriteLine();

Console.WriteLine("First Letter Capital words:");

Console.WriteLine(Regex.Replace(words, @"\w+", (m) => {

//change the first letter to capitalize

if(type == )

return m.Value[].ToString().ToUpper() + m.Value.Substring();

else

{

string keywordslist = " select from where and or join left right full on ";

if(keywordslist.IndexOf(" " + m.Value + " ")>-)

return m.Value.ToUpper();

else

return m.Value;

}

}));

}

public static void Main(string[] args)

{

regexReplaceDemo();

regexReplaceDemo();

}

}

最新文章

  1. Eclipse 中Tomcat 启动 与直接启动Tomcat的区别
  2. [LintCode] Interleaving Positive and Negative Numbers
  3. Union与union all区别
  4. Unity学习资源
  5. c++ primer (5)1
  6. get started with laravel
  7. MySQL与unix时间问题
  8. mybatis配置文件xxxx.xml中缺失返回类型的后果A query was run and no Result Maps were found
  9. 实现Windows数据绑定
  10. [扩展推荐] —— Laravel Log 增强
  11. hello2代码的简单分析
  12. tomcat中浏览器重新选择下.就解决该问题了
  13. 剑指offer题目java实现
  14. gpu/mxGPUArray.h” Not Found
  15. 汇编 OD 调式
  16. oracle 复制表结构表数据
  17. 几何+线段交点+spfa(POJ1066)
  18. 某DP题目3
  19. [misc]如何在嵌入式平台使用printf功能
  20. mac os下载安装jmeter

热门文章

  1. Python入门笔记(8):列表
  2. kFreeBsd 国内开源镜像站汇总
  3. windows下react-native环境搭建
  4. Qt 框架 开发HTTP 服务器 开发记录
  5. No.012:Integer to Roman
  6. javascript 之拼接html字符串
  7. jQuery中的事件冒泡
  8. $(document).ready()即$()方法和window.onload方法的比较
  9. T-SQL的回车和换行符(SQL)
  10. ThreadLocal,Java中特殊的线程绑定机制