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,目前还是 ...
随机推荐
- 重新想象 Windows 8 Store Apps (67) - 后台任务: 推送通知
[源码下载] 重新想象 Windows 8 Store Apps (67) - 后台任务: 推送通知 作者:webabcd 介绍重新想象 Windows 8 Store Apps 之 后台任务 推送通 ...
- [Xamarin.Android] 自定义控件
[Xamarin.Android] 自定义控件 前言 软件项目开发的过程中,免不了遇到一些无法使用内建控件就能满足的客户需求,例如:时速表.折线图...等等.这时开发人员可以透过自定义控件的方式,为项 ...
- [Architecture Pattern] Repository实作查询功能
[Architecture Pattern] Repository实作查询功能 范例下载 范例程序代码:点此下载 问题情景 在系统的BLL与DAL之间,加入Repository Pattern的设计, ...
- 从网络中获取图片显示到Image控件并保存到磁盘
一.从网络中获取图片信息: /// <summary> /// 获取图片 /// </summary> /// <param name="url"&g ...
- JDK8 API文档(下载)
DK API文档 java SE 8 API文档: http://www.oracle.com/technetwork/java/javase/documentation/jdk8-doc-downl ...
- abs()函数的返回值问题
转载原文地址:http://www.cnblogs.com/webary/p/4967868.html 在牛客网看到一道关于abs()函数返回值的题目,见下图,当时还没反应过来,第一反应是:自从我开始 ...
- find locate
locate执行前先 updatedb 然后locate vstore 就可以了 find 加 -name 比如 find -name vstore 按理说 locate要快点,毕竟是数据库嘛 一:l ...
- Windows下查看端口占用
最近在重新安装Mysql的时候,发现3306默认端口被占用了.类似的情况常常遇到,想查看到底是哪个程序把这个端口占用了. 下面是我google找到的方法,和大家分享. 1. 首先,使用netstat ...
- Effective Java 70 Document thread safety
Principle The presence of the synchronized modifier in a method declaration is an implementation det ...
- springMVC 接收数组参数,mybatis 接收数组参数,mybatis批量插入/批量删除案例
案例是给一个用户赋予多个权限,多个权限用其对应的主键 id 为参数,组成了 一个id数组,传给springMVC,然后springMVC传给mybatis,然后mybatis批量插入.其实类似的场景还 ...