【LABVIEW到C#】3》String的操作之Match Pattern Funtion.vi

C#实现如下
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions; namespace DEMO
{
class Darrenstring
{
public class Matchpattern:Darrenstring
{
private string text;
private string pattern;
private int index;
public bool ismatch;
public Matchpattern(string Text, string Pattern)
{
text = Text;
pattern = Pattern;
Match a = Regex.Match(text,pattern);
index=a.Index;
ismatch = a.Success;
}
public int Index()
{
return index;
}
public string Before()
{
if (ismatch)
{
return (text.Substring(, index));
}
else return null;
}
public string After()
{
if (ismatch)
{
return (text.Substring(index + pattern.Length, text.Length - pattern.Length-index));
}
else return null;
}
}
}
}
类写好后 我们来做个试验 新建个winform程序

程序部分代码如下:
private void Confirm_Click(object sender, EventArgs e)
{
Darrenstring.Matchpattern A = new Darrenstring.Matchpattern(Source.Text, Terminal.Text);
//Terminal.Text = Convert.ToString(A.Index());
before1.Text = A.Before();
After.Text = A.After();
IsMatched.Checked = A.ismatch;
}
运行后结果图如下:

效果不错功能实现
MSDN资料参考
System.String.RegularExpressions命名空间说明 https://msdn.microsoft.com/zh-cn/library/System.Text.RegularExpressions(v=vs.80).aspx
Regex类说明 https://msdn.microsoft.com/zh-cn/library/system.text.regularexpressions.regex(v=vs.80).aspx
【LABVIEW到C#】3》String的操作之Match Pattern Funtion.vi的更多相关文章
- 【LABVIEW到C#】4》String的操作之Search and Replace.vi
C#封装如下: public class SearchAndRepalce : Darrenstring { public bool replaced; private string stringou ...
- LabVIEW之生产者/消费者模式--队列操作 彭会锋
LabVIEW之生产者/消费者模式--队列操作 彭会锋 本文章主要是对学习LabVIEW之生产者/消费者模式的学习笔记,其中涉及到同步控制技术-队列.事件.状态机.生产者-消费者模式,这几种技术在在本 ...
- redis 的使用 (基础, key操作, string类型操作)
使用redis set 类型: 没有重复元素 list 链表类型 有重复累型 sort set 类型 没有重复元素 1.1 存储数据 读取数据 // 数据储存在 内存中 set name laowen ...
- Redis系列-存储篇string主要操作函数小结
通过上两篇的介绍,我们的redis服务器基本跑起来.db都具有最基本的CRUD功能,我们沿着这个脉络,开始学习redis丰富的数据结构之旅,当然先从最简单且常用的string开始. 1.新增 a)se ...
- string的操作
除了顺序容器共有的操作之外,string类型还提供了一些额外的操作.这些操作中的大部分要么是提供string类和C风格字符数组之间的相互转换,要么是增加了允许我们用下标代替迭代器的版本. 构造stri ...
- Library string type(2)——关于String的操作
关于string的定义,请参阅博文http://blog.csdn.net/larry233/article/details/51483827 string的操作 s.empty() //Return ...
- 022 StringTokenizer替换掉String的操作
一:说明 1.说明 String的操作特别消耗内存,所以可以考虑优化. 二:程序 1.程序修改 这部分程序属于Mapper端的程序,稍微优化一下. 2.程序 //Mapper public stati ...
- LabVIEW之生产者/消费者模式--队列操作
LabVIEW之生产者/消费者模式--队列操作 彭会锋 本文章主要是对学习LabVIEW之生产者/消费者模式的学习笔记,其中涉及到同步控制技术-队列.事件.状态机.生产者-消费者模式,这几种技术在在本 ...
- 字符串中判断存在的几种模式和效率(string.contains、string.IndexOf、Regex.Match)
通常情况下,我们判断一个字符串中是否存在某值常常会用string.contains,其实判断一个字符串中存在某值的方法有很多种,最常用的就是前述所说的string.contains,相对来说比较常用的 ...
随机推荐
- The OpenCV Coding Style Guide
https://github.com/opencv/opencv/wiki/Coding_Style_Guide
- Java栈(Stack)和堆(Heap)
In the following code public void Method1() { int i = 4; int y = 2; class1 cls1 = new class1(); } He ...
- SQL小练习
1.现在有两张表订单表TB_ORDER,包括字段:order_id(订单号),username(用户名),amount(订单金额),order_time(下单时间), product_id(商品ID) ...
- 列表(List) 的增删改查及其他方法
一.列表的简介 列表是python中的基础数据类型之一,其他语言中也有类似于列表的数据类型,比如js中叫数组,他是以[ ]括起来,每个元素以逗号隔开,而且他里面可以存放各种数据类型比如:li = ...
- Deep Learning -- 数据增强
数据增强 在图像的深度学习中,为了丰富图像训练集,更好的提取图像特征,泛化模型(防止模型过拟合),一般都会对数据图像进行数据增强,数据增强,常用的方式,就是旋转图像,剪切图像,改变图像色差,扭曲图像特 ...
- QT解析嵌套JSON表达式
QT5开发环境集成了解析JSON表达式的库.使用很方便. 友情提示一下,好像在QT4环境里.须要到官网下载相关的库文件才干使用解析功能.话不多说,上代码 1.在pro文件里增加 QT += scrip ...
- Kettle-1-安装配置
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/wl101yjx/article/details/32921691 写在前面一: 数据仓库ETL工具有 ...
- Red Hat Enterprise Linux
以下是支持 Docker 的 RHEL 版本: Red Hat Enterprise Linux 7 (64-bit) Red Hat Enterprise Linux 6.5 (64-bit) 或更 ...
- docker的安装以及jdk和tomcat的环境配置
准备工作:需要Linux kernel 3.8支持查看linux内核的版本:root@ubuntu-dev:~# cat /proc/version查看linux版本:root@ubuntu-dev: ...
- HDU1165: Eddy's research II(递推)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1165 果断不擅长找规律啊,做这种题静不下心来. Ackermann function can be def ...