string str = "姓名(男)年龄#20";
string[] items = str.Split('(', ')', '#');
string[] items = str.Split('(', ')', '#');
解决方案 »
- 向大牛请教方案实现路线,请高手指点,非常感谢!
- 关于Process类的问题..~~>_<~~
- 准备用C#写一个winfom计算器,想问问那个窗体中的显示屏
- winform下系统自动转换全角与半角
- 提问关于临时文件的问题
- 急问一个小问题:请问如何在Form1 的 button1_click事件中使Form2 中的 Timer1 的 Enable 属性改变啊???
- OWC技术,解决 EXCEL报表格式问题 (等待。。。)
- c# 中如何获得mssql中某字段内容为<long text>的值?
- 求一存储过程的思路
- 大家一起探讨一下C#应用程序的效率。
- 多线程之自定义线程问题 望大虾们指点迷津
- C#中数组下标为-1代表什么意思
string s="姓名(男)年龄#20";
string[] s2=s.split('#');
string s3=s2[1]; //这就是年龄的数字如果不放心,可以检测一下是不是数字,直接转换try
{
int age=convertto.int32(s3);
messagebox.show("获取年龄成功");
}
catch(exception ex)
{
messagebox.show("获取年龄失败");
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
namespace sxLdfang
{
class Program
{
static void Main(string[] args)
{
string html = @"张三(男)18#20
张三疯(男)88#28
";
string pattern = @"(?m)^(?<xm>[^(]+)\([^)]+\)(?<nl>\d+)#(?<num>\d+)$";
MatchCollection mc = Regex.Matches(html, pattern);
foreach (Match m in mc)
{
Console.WriteLine(" xm:" + m.Groups["xm"].Value);
Console.WriteLine(" nl:" + m.Groups["nl"].Value);
Console.WriteLine(" num:" + m.Groups["num"].Value);
Console.WriteLine();
}
Console.ReadKey();
}
}
}
运行结果:
xm:张三
nl:18
num:20 xm:张三疯
nl:88
num:28
@"(?<=姓名\(.*?\)).*?#\d+"