【LABVIEW到C#】3》String的操作之Match Pattern Funtion.vi
2024-08-30 03:01:47
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
最新文章
- div 添加滚动条
- Android SurfaceView的生命周期
- org.apache.hadoop.hdfs.server.namenode.SafeModeException: Cannot create directory /user/hive/warehouse/page_view. Name node is in safe mode
- 【CITE】C#默认以管理员身份运行程序实现代码
- POJ 1410 Intersection(判断线段交和点在矩形内)
- jquery foreach
- java图片处理
- PHP金字塔的输出
- BZOJ 1831 逆序对
- 【POJ3208】 (DP)
- 服务 Service 基本介绍
- 让asp.net网站支持多语言,使用资源文件
- 如何用Python在豆瓣中获取自己喜欢的TOP N电影信息
- Python 妙用heapq
- JAVA之旅(二十)—HashSet,自定义存储对象,TreeSet,二叉树,实现Comparator方式排序,TreeSet小练习
- MVC中一般为什么用IQueryable而不是用IList?
- 安装pyspider遇到的坑
- python 0007
- pythonGUI编程-tkinter
- Linux 文件系统介绍
热门文章
- showslow / YSlow for PhantomJS/slimerjs(gecko)/phantomas
- Java 之多线程通信(等待/唤醒)
- 洛谷 [BJOI2012]最多的方案
- 面试常见的selenium问题
- 《深入理解Linux网络技术内幕》阅读笔记 --- 路由表
- python逆向工程:通过代码生成类图
- 0406-服务注册与发现-客户端feign-使用、配置、日志、timeout
- 解决linux下python多版本兼容问题?
- CKEditor的下载、配置与使用
- beego——获取参数