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 文件和文件组

    文件和文件组简介 在SQL Server中,数据库在硬盘上的存储方式和普通文件在Windows中的存储方式没有什么不同,仅仅是几个文件而已.SQL Server通过管理逻辑上的文件组的方式来管理文件. ...

  2. C#实现的18位身份证格式验证算法

    18位身份证标准在国家质量技术监督局于1999年7月1日实施的GB11643-1999<公民身份号码>中做了明确的规定. GB11643-1999<公民身份号码>为GB1164 ...

  3. C#语法糖

    首先需要声明的是“语法糖”这个词绝非贬义词,它可以给我带来方便,是一种便捷的写法,编译器会帮我们做转换:而且可以提高开发编码的效率,在性能上也不会带来损失.这让java开发人员羡慕不已,呵呵. 1.  ...

  4. csharp: Speech

    Speech SDK 5.1https://www.microsoft.com/en-us/download/details.aspx?id=10121 detects mobile devices ...

  5. ACdream 1214---矩阵连乘

    ACdream 1214---矩阵连乘 Problem Description You might have noticed that there is the new fashion among r ...

  6. [Xamarin.Android] Support Library Tips

    [Xamarin.Android] Support Library Tips Support Library支持内容 Xamarin Support Library每个版本支持.那些组件,可以参考这份 ...

  7. RHEL7进程管理

    进程概念 名称 说明 程序 一组指令的集合 进程 程序的执行就是进程也可以把进程看成一个独立的程序在内存中有其对应的代码空间和数据空间,一个进程所拥有的数据和代码只属于自己进程是资源分配的基本单位,也 ...

  8. CSS3选择器(一)

    E[att^='val'] 选择属性值以val开头的任何字符 E[att$='val'] 选择属性值以val结尾的任何字符 E[att*='val'] 选择属性值包含val的任何字符 :root HT ...

  9. SQL Server 分组 去除从复列

    下面先来看看例子: table表 字段1 字段2 id        name 1           a 2           b 3           c 4           c 5    ...

  10. IOS中(Xcode) DEBUG模式(RELEASE模式)控制NSLog输出,NSLog两种不同情况的输出方式

    [新年新气象,2016/01/04] 俺们在开发IOS程序过程中,经常需要用到NSLog输出一些信息,甚至有的开发过程,必须在控制台查看输出,有经验的程序员通过控制台输出就能知道整个数据交互的一个流程 ...