Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从LDAP错误消息中提取数据值_C#_Regex - Fatal编程技术网

C# 从LDAP错误消息中提取数据值

C# 从LDAP错误消息中提取数据值,c#,regex,C#,Regex,我有一个类型为DirectoryServicesCOMException的异常,我需要从它的ExtendedErrorMessage属性中提取数据值 下面是一个来自ExtendedErrorMessage属性的示例测试: 8009030C:ldaper:DSID-0C0904DC,注释:AcceptSecurityContext错误,数据701,v1db1 我需要字符串中的701 仅供参考,我从SO处找到以下消息: 我成功地使用了LastIndexOf'data'和next','after La

我有一个类型为
DirectoryServicesCOMException
的异常,我需要从它的
ExtendedErrorMessage
属性中提取数据值

下面是一个来自
ExtendedErrorMessage
属性的示例测试:

8009030C:ldaper:DSID-0C0904DC,注释:AcceptSecurityContext错误,数据701,v1db1

我需要字符串中的
701

仅供参考,我从SO处找到以下消息:

我成功地使用了LastIndexOf'data'和next','after LastIndexOf'data'组合,但正在寻找一个更干净的解决方案


谢谢。

如果您想要的结果总是在最后一个逗号之前,并且只有数字,那么您可以使用枚举和类似的方法

string s = "8009030C: LdapErr: DSID-0C0904DC, comment: AcceptSecurityContext error, data 701, v1db1";
string[] array = s.Split(new []{','},
                         StringSplitOptions.RemoveEmptyEntries); 
string s1 = array[array.Length - 2]; // This will be " data 701"
string finalstring = Regex.Match(s1, @"\d+").Value; // \d+ is for only integer numbers
Console.WriteLine(finalstring); // Prints 701
这里有一个