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();

}

}

dotnet use regex two samples的更多相关文章

  1. 【ASP.NET Core分布式项目实战】(五)Docker制作dotnet core控制台程序镜像

    Docker制作dotnet core控制台程序镜像 基于dotnet SDK 新建控制台程序 mkdir /home/console cd /home/console dotnet new cons ...

  2. dotnet core 使用 CoreRT 将程序编译为 Native 程序

    现在微软有一个开源项目 CoreRT 能通过将托管的 .NET Core 编译为单个无依赖的 Native 程序 这个项目现在还没发布,但是能尝试使用,可以带来很多的性能提升 使用 CoreRT 发布 ...

  3. .NET 2.0 参考源码索引

    http://www.projky.com/dotnet/2.0/Microsoft/CSharp/csharpcodeprovider.cs.htmlhttp://www.projky.com/do ...

  4. .NET Core系列 :4 测试

    2016.6.27 微软已经正式发布了.NET Core 1.0 RTM,但是工具链还是预览版,同样的大量的开源测试库也都是至少发布了Alpha测试版支持.NET Core, 这篇文章 The Sta ...

  5. .NET Core 2.0 应用程序大小减少50%

    .NET Core 2.0减小体积瘦身官方工具 IL Linker. IL Linker 来源于mono的linker  https://github.com/mono/linker,目前还是预览版本 ...

  6. .NET Core单文件发布静态编译AOT CoreRT

    .NET Core单文件发布静态编译AOT CoreRT,将.NET Core应用打包成一个可执行文件并包含运行时. 支持Windows, MacOS and Linux x64 w/ RyuJIT ...

  7. ASP.NET Core在Azure Kubernetes Service中的部署和管理

    目录 ASP.NET Core在Azure Kubernetes Service中的部署和管理 目标 准备工作 注册 Azure 账户 AKS文档 进入Azure门户(控制台) 安装 Azure Cl ...

  8. 树莓派3B+上运行.Net Core项目

    最近买了个树莓派3B+,准备把自己写的一个.Net Core爬虫挂在上面跑 买之前没有想到树莓派因为是今年新出的,导致驱动以及系统啥的都不是很完善,导致走了很多弯路,早知道买树莓派3就不用那么多折腾了 ...

  9. .NET Core 2.0应用程序大小减少50%

    .NET Core 2.0应用程序减小体积瘦身官方工具 IL Linker. IL Linker 来源于mono的linker  https://github.com/mono/linker,目前还是 ...

随机推荐

  1. 用javascript去掉字符串空格的办法

    今天遇到了以关于JavaScript 中怎么去掉 字符串中前后两段的空格 ,我只好向就得js中也后Trim() 函数,后来试试了不 行,就网上找了下解决方法,其中用到了正则表达式 ,整理了下: < ...

  2. csharp: json to csharp

    http://json2csharp.com/ http://jsonclassgenerator.codeplex.com/ http://jsonutils.com/ JSON生成类文件 http ...

  3. platform总线globalfifo驱动

    功能是使用内存的4k单元,实现读,写,偏移,清除. /************************************************************************* ...

  4. 树状数组---Squared Permutation

    BNUOJ   51636 最近,无聊的过河船同学在玩一种奇怪的名为“小Q的恶作剧”的纸牌游戏. 现在过河船同学手有张牌,分别写着,打乱顺序之后排成一行,位置从左往右按照标号. 接下来小Q同学会给出个 ...

  5. PhpStorm的open in browser怎么修改端口和相对路径

    昨天下班后,在电脑安装phpstorm.xampp安装正常,但是在phpstorm上直接打开网站文件一直报错,一直报错502.我感觉好奇快,怎么会报错呢.后面我用hbuild打开文件,在浏览器显示正常 ...

  6. FPSCalc——简单FPS观测类

    利用Unity做的手游项目很多时候要保证流畅度,流畅度最直观的表现就是帧率FPS.Unity编辑器模式下的帧率观测几乎没有意义,所以还是自己实现的好. 这里给一个前人写的类,我几乎原封不动,该类只有一 ...

  7. ArcGIS中的style样式的使用

    MapGIS安装包大小(以M计算)与ArcGIS (以G计算)在数量级存在差异,就可以隐约知道ArcGIS功能的强大.ArcGIS更注重重用(比如符号库.模块等).数据与制图分离(尤其是制图表达最能体 ...

  8. SharePoint 2010 文档管理之过期归档工具

    前言:使用过SharePoint的人都知道,SharePoint对于操作是便捷的,但是对于数据量承载却是不令人满意的,这样,就要求我们需要更加合理的使用,规范大家的使用规则和习惯,所以,定期清理不必要 ...

  9. 实验12:Problem D: 判断两个圆之间的关系

    Home Web Board ProblemSet Standing Status Statistics   Problem D: 判断两个圆之间的关系 Problem D: 判断两个圆之间的关系 T ...

  10. 桥牌笔记L4D17:小心阻塞

    南打3NT. 西的首攻会有3墩黑桃.3墩方块.2付梅花,共8墩到手.看来方块如果3-2分布的话,非常容易就能超一完成. 所以要想着4-1分布的安全打法. 第一墩庄家拿了黑桃J后,明手的黑桃A会阻塞,庄 ...