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,目前还是 ...
随机推荐
- Java中处理异常中return关键字
Java中,执行try-catch-finally语句需要注意: 第一:return语句并不是函数的最终出口,如果有finally语句,这在return之后还会执行finally(return的值会暂 ...
- SQL Server 全局变量
SQL Server中所有全局变量都使用两个@符号作为前缀 --1.@@error 最后一个T-SQL错误的错误号(目的是或得违反约束的错误号) insert into Subject values( ...
- Mysql基本数据操作
一.mysql中的逻辑对象 mysqld(process_id(threads)+memory+datadir)-->库-->表-->记录(由行与列组成) 什么是关系型数据库:表与表 ...
- SharePoint 2013 开启访问请求
1.通常,我们进入SharePoint 2013站点,如果没权限会提示该站点未被共享,而没有切换账号或者申请访问,实在是很流氓:其实,SharePoint为我们提供了访问请求页面,但是可能需要手动开启 ...
- HTML中图片热区的使用
在HTML中有一个具有把图片划分成多个作用区域,并链接到不同网页的标记,那就是 <area>地图作用区域标记. <area>标记主要用于图像地图,通过该标记可以在图像地图中设定 ...
- ubuntu下nagios配置
参考文献: http://www.cnblogs.com/mchina/archive/2013/02/20/2883404.html http://my.oschina.net/duangr/blo ...
- Spring中配置数据源的4种形式(转)
原文http://blog.csdn.net/orclight/article/details/8616103 不管采用何种持久化技术,都需要定义数据源.Spring中提供了4种不同形式的 ...
- iOS程序启动的过程及原理
iOS程序启动的过程及原理 文字部分 先执行main函数,main内部会调用UIApplicationMain函数 UIApplicationMain函数里面做了什么事情??? 1> 创建UIA ...
- OC语言-04-OC语言-核心语法
一.点语法 1> 基本使用 点语法本质上是set方法/get方法的调用 2> 使用注意 若出现在赋值操作符的右边,在执行时会转换成get方法 若出现在赋值操作符的左边,在执行时会转换成se ...
- Mysql中的视图
什么是视图 通俗的讲,视图就是一条SELECT语句执行后返回的结果集.所以我们在创建视图的时候,主要的工作就落在创建这条SQL查询语句上. 视图的特性 视图是对若干张基本表的引用,一张虚表,查询语句执 ...