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. SQL Server 性能调优(一)——从等待状态判断系统资源瓶颈【转】

    转载自:http://blog.csdn.net/dba_huangzj/article/details/7607844#comments 通过DMV查看当时SQL SERVER所有任务的状态(sle ...

  2. PHP实现过滤各种HTML标签

    首先分享一些比较常见的 $str=preg_replace("/<s*imgs+[^>]*?srcs*=s*(''|")(.*?)\1[^>]*?/?s*> ...

  3. 互联网产品团队中Web前端工程师的重要性

    国内外各大互联网公司,都有UEx/d|UCD|CDC(Customer Research & User Experience Design Center)团队. 在很多公司会认为,合格的产品经 ...

  4. mybatis mapper association collection

    1.Question Description: sometimes, POJO bean contains another bean or collection as property, it's s ...

  5. Sass学习之路(4)——不同样式风格的输出方式

    因为每个前端工程师编写代码的风格都不太一样,所以Sass的编译也非常人性化的提供了不同风格的编译方式,主要分为4种. 比如下面这一段Sass代码,我们来看看在不同风格下,会编译成什么样吧: nav { ...

  6. SQL Server Merge语句的使用

    Merge关键字在SQL Server 2008被引入,它能将Insert,Update,Delete简单的并为一句.MSDN对于Merge的解释非常的短小精悍:”根据与源表联接的结果,对目标表执行插 ...

  7. andriod 动态创建控件

    Button btNext=(Button)findViewById(R.id.next); btNext.setOnClickListener(new Button.OnClickListener( ...

  8. SharePoint 使用代码为页面添加WebPart

    传统的SharePoint实施中,我们通常会创建SharePoint页面,然后添加webpartzone,而后在上面添加webpart:但是有些情况下,也要求我们使用代码,将webpart添加到相应w ...

  9. iOS 获取UIView所在的VIewController

    写程序的时候我们经常要封装代码,当你封装了一个UIView的子类里需要调用所在ViewController的方法用如下代码调取所在的VIewController #pragma mark - 获取所在 ...

  10. 得到设备是何种iPhone设备 + 怎么获得启动页面图片

    一.前言 今天做一个功能,需要动态的获得启动页,然后根据不同设备去使用不用的启动页图片. 二.正文 常规来说,我们直接判断是何种设备,然后通过name去获得图片选择性加载即可.但是实际上遇到的两个问题 ...