dotnet use regex two samples
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的更多相关文章
- 【ASP.NET Core分布式项目实战】(五)Docker制作dotnet core控制台程序镜像
Docker制作dotnet core控制台程序镜像 基于dotnet SDK 新建控制台程序 mkdir /home/console cd /home/console dotnet new cons ...
- dotnet core 使用 CoreRT 将程序编译为 Native 程序
现在微软有一个开源项目 CoreRT 能通过将托管的 .NET Core 编译为单个无依赖的 Native 程序 这个项目现在还没发布,但是能尝试使用,可以带来很多的性能提升 使用 CoreRT 发布 ...
- .NET 2.0 参考源码索引
http://www.projky.com/dotnet/2.0/Microsoft/CSharp/csharpcodeprovider.cs.htmlhttp://www.projky.com/do ...
- .NET Core系列 :4 测试
2016.6.27 微软已经正式发布了.NET Core 1.0 RTM,但是工具链还是预览版,同样的大量的开源测试库也都是至少发布了Alpha测试版支持.NET Core, 这篇文章 The Sta ...
- .NET Core 2.0 应用程序大小减少50%
.NET Core 2.0减小体积瘦身官方工具 IL Linker. IL Linker 来源于mono的linker https://github.com/mono/linker,目前还是预览版本 ...
- .NET Core单文件发布静态编译AOT CoreRT
.NET Core单文件发布静态编译AOT CoreRT,将.NET Core应用打包成一个可执行文件并包含运行时. 支持Windows, MacOS and Linux x64 w/ RyuJIT ...
- ASP.NET Core在Azure Kubernetes Service中的部署和管理
目录 ASP.NET Core在Azure Kubernetes Service中的部署和管理 目标 准备工作 注册 Azure 账户 AKS文档 进入Azure门户(控制台) 安装 Azure Cl ...
- 树莓派3B+上运行.Net Core项目
最近买了个树莓派3B+,准备把自己写的一个.Net Core爬虫挂在上面跑 买之前没有想到树莓派因为是今年新出的,导致驱动以及系统啥的都不是很完善,导致走了很多弯路,早知道买树莓派3就不用那么多折腾了 ...
- .NET Core 2.0应用程序大小减少50%
.NET Core 2.0应用程序减小体积瘦身官方工具 IL Linker. IL Linker 来源于mono的linker https://github.com/mono/linker,目前还是 ...
随机推荐
- UVA 10090 - Marbles 拓展欧几里得
I have some (say, n) marbles (small glass balls) and I am going to buy some boxes to store them. The ...
- 学习Scala: 初学者应该了解的知识
Scala开发参照清单 这里列出在开发一个Scala工程中需要参照的资料. 官网网站 http://www.scala-lang.org/ 文档网站 http://docs.scala-lang.or ...
- js小数计算小数点后显示多位小数(转)
首先写一个demo 重现问题,我使用的是一个js在线测试环境[打开] 改写displaynum()函数 function displaynum(){var num = 22.77;alert(num ...
- SharpGL学习笔记(十八) 解析3ds模型并显示
笔者设想的3D仿真中的元件,是不可能都是“画”出来的.这样就玩复杂了,应该把任务分包出去,让善于制作模型的软件来制作三维模型,我们只需要解析并且显示它即可. 3dsmax制作三维模型的方便,快捷,专业 ...
- c#多线程生产者消费者(手稿)
屋舍简陋,隔壁的娃娃哭了一晚,心中无恶意纯中性的想,有病就赶紧带孩子去看医生吧,能哭这么久估计孩子真的不舒服.
- css3属性小结
/*border-radius*/ .demo2{ border:2px solid #a1a1a1; padding:10px 40px; background:#dddddd; width:300 ...
- 新技能,利用Reflector来修改dll引用
继上次<ArcObject10.1降级至10.0>又遇到版本降级问题.通常的方式有: 方案一:重新编译 将源代码加载到解决方案中,修改相应dll的版本,比较快捷的方式是多选后,设置属性中特 ...
- ArcEngine尝试读取或写入受保护的内存
先说一下我的开发环境: Win10 + ArcGIS10.0 + ArcEngine10.0 + Framework4.0 今天调用新的GP工具则出现"尝试读取或写入受保护的内存.这通常指示 ...
- C#中的Mutex对象认识
我们知道,有些应用程序可以重复打开,有些只能打开一个,我以前写的程序为了防止用户打开多个程序,都是去遍历Process 查找进程的方式,现在看起来真是不专业,今天看大神的破解分析文章时,认识了mute ...
- [leetcode] Bitwise AND of Numbers Range
Bitwise AND of Numbers Range Given a range [m, n] where 0 <= m <= n <= 2147483647, return t ...