当切割字符串的是单个字符时可使用String.Split

string strSample="ProductID:20150215,Categroy:Food,Price:15.00";
string[] sArray=strSample.Split(',');    //注意,这里用的是单引号,而非双引号

当切割字符串的是多个字符时只能使用Regex.Split
string strSample="ProductID:20150215$_$Categroy:Food$_$Price:15.00";
string[] sArray=Regex.Split(strSample,@"\$_\$",RegexOptions.IgnoreCase);  //注意,需做特殊字符的转义。另外Regex 在System.Text.RegularExpressions 命名空间下。

字符串切分 String.Split 和 Regex.Split(小技巧)的更多相关文章

  1. 字符串切分 String.Split 和 Regex.Split

    当切割字符串的是单个字符时可使用String.Split string strSample="ProductID:20150215,Categroy:Food,Price:15.00&quo ...

  2. Regex.Split

    private static List<int> GetThemeIds(string themeList) { const string split = "!===!" ...

  3. C#入门篇6-3:字符串操作 string的ToString() Split()和Copy()方法

    //ToString()方法 public static void OutPut() { //字符型转换 转为字符串 Console.WriteLine(.ToString("n" ...

  4. C#实现字符串按多个字符采用Split方法分割

    原文:C#实现字符串按多个字符采用Split方法分割 String字符串如何按多个字符采用Split方法进行分割呢?本文提供VS2005和VS2003的实现方法,VS2005可以用下面的方法: str ...

  5. C#中Split分隔字符串的应用(C#、split、分隔、字符串)

    转载地址 .用字符串分隔: using System.Text.RegularExpressions; string str="aaajsbbbjsccc"; string[] s ...

  6. C# Split的用法,Split分割字符串

    C# Split的用法,Split分割字符串 分割单个字串:string str="来自张三的亲切问候!;string[] strarry=str.Split(new string[] { ...

  7. 字符串中判断存在的几种模式和效率(string.contains、string.IndexOf、Regex.Match)

    通常情况下,我们判断一个字符串中是否存在某值常常会用string.contains,其实判断一个字符串中存在某值的方法有很多种,最常用的就是前述所说的string.contains,相对来说比较常用的 ...

  8. js进阶js中支持正则的四个常用字符串函数(search march replace split)

    js进阶js中支持正则的四个常用字符串函数(search march replace split) 一.总结 代码中详细四个函数的用法 search march replace split 二.js进 ...

  9. java字符串分解 StringTokenizer用法(比split()方法效率高)

    Java中substring方法可以分解字符串,返回的是原字符串的一个子字符串.如果要讲一个字符串分解为一个一个的单词或者标记,StringTokenizer可以帮你. int countTokens ...

随机推荐

  1. 手动制作openstack windows镜像

    https://docs.openstack.org/image-guide/windows-image.html 这里以 windows 2008为例: 准备工作: 1准备好windows 2008 ...

  2. Linux平台下停止后台进程脚本编写

    1.场景说明 [root@master ~]# jps -m 33050 Jps -m 3299 NameNode 3747 ResourceManager 9028 ConsoleConsumer  ...

  3. Linux之chown

    命令功能: chown将指定文件的拥有者改为指定的用户或组,用户可以是用户名或者用户ID:组可以是组名或者组ID:文件是以空格分开的要改变权限的文件列表,支持通配符.系统管理员经常使用chown命令, ...

  4. 使用 Visual Studio 分析器找出应用程序瓶颈

    VS的性能分析工具 性能分析工具的选择 打开一个“性能分析”的会话:Debug->Start Diagnotic Tools Without Debugging(或按Alt+F2),VS2013 ...

  5. Delphi:窗体的扩展样式GWL_EXSTYLE用于SetWindowLong

    SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_TRANSPARENT or WS_EX_ ...

  6. qt编程

    http://www.zhihu.com/question/20054048 http://www.cnblogs.com/luoshupeng/archive/2011/05/01/2033743. ...

  7. 注册表项关于start参数的说明

    start = {0,1,2,3,4}0 == 由核心装载器装载1 == 由I/O子系统装载2 == 自动启动3 == 手工启动4 == 禁止启动

  8. angular的组件通信

    参见这里   总结如下: @Input和@Ouptut 获取父实例,获取子实例 通过service共享数据 发送事件EventEmitter(个人喜欢angular-event-service) rx ...

  9. DS二叉树--二叉树之父子结点

    题目描述 给定一颗二叉树的逻辑结构如下图,(先序遍历的结果,空树用字符‘0’表示,例如AB0C00D00),建立该二叉树的二叉链式存储结构. 编写程序输出该树的所有叶子结点和它们的父亲结点 输入 第一 ...

  10. what's the difference between grouping and facet in lucene 3.5

    I  found in lucene 3.5 contrib folder two plugins: one is grouping, the other is facet. In my option ...