简体   繁体   English

如何从资源分配中获取资源名称

[英]How to get resource name from resource assignment

I'm using MPXJ to read mpp file. 我正在使用MPXJ读取mpp文件。 I have a resource assignment string as below: 我有一个资源分配字符串,如下所示:

string st = [[Resource Assignment task=Sign contract and update data resource=
X.C. Information Management start=Thu Jun 09 08:00:00 ICT 2014 finish=Thu Jun 05 17:
00:00 ICT 2014 duration=32.0h workContour=null]]

I want to get resource name from the above string ( XC Information Management ). 我想从上面的字符串中获取资源名称( XC信息管理 )。
Currently, I use the code: 目前,我使用以下代码:

st.Split('=')[2].Replace(" start", ""); // return X.C. Information Management<br/>

I think use regular expression as well as, howerver, I don't have any ideas to implement it. 我认为使用正则表达式以及,但是,我没有实现它的任何想法。
Please help me if you can. 如果可以,请你帮助我。

Thanks 谢谢

If the information you want is wrapped in bold tags ( <b> & </b> ), and there are no other bold tags in your string, then this regex should work: 如果所需信息用粗体标签( <b></b> )包裹,并且字符串中没有其他粗体标签,则此正则表达式应该起作用:

(?<=<b>).*(?=<\/b>)

See here 这里

In C#, you could do something like this: 在C#中,您可以执行以下操作:

Regex regex = new Regex(@"(?<=<b>).*(?=<\/b>)");
string testString = @"*string st = [[Resource Assignment task=Sign contract and update data resource=<b>X.C. Information Management</b> start=Thu Jun 09 08:00:00 ICT 2014 finish=Thu Jun 05 17:00:00 ICT 2014 duration=32.0h workContour=null]]*";
string text = regex.Match(testString).Value;

And text will equal XC Information Management 而且text将等于XC Information Management

EDIT: Ok - so the OP removed the <b> tags, but the principle is still very much the same. 编辑:好的-所以OP删除了<b>标记,但是原理仍然非常相同。 Just replace the <b> tags with an appropriate marker that you know will come before and after the string you are looking for. 只需更换<b>知道会前和后弦你正在寻找一个适当的标记标签。 For example: 例如:

(?<=resource=).*(?=start)

You can use a Regular Expression like this: 您可以使用以下正则表达式:

resource=(.*)\sstart=

The information would be in the group not in the matched string: 该信息将在组中而不在匹配的字符串中:

Regex.Match(input, "resource=(.*)\sstart=").Groups[1].Value

Interesting... it looks like the OP has retrieved a Resource instance from MPXJ, and is using the toString() method of the instance to look at the data, for example: 有趣的是...好像OP从MPXJ检索了Resource实例,并正在使用实例的toString()方法查看数据,例如:

Project file;
// Some code to read the project

// Retrieve the first resource
Resource resource = file.getResourceByUniqueID(1);
string st = resource.toString();

This is not a great idea... the toString() method is intended to provide debugging information only. 这不是一个好主意... toString()方法仅用于提供调试信息。

A better approach would be to call a method to retrieve the name directly: 更好的方法是调用一种方法直接检索名称:

string st = resource.getName();

You can find API documentation for MPXJ here which will give you an idea of the methods available on each object, if you IDE doesn't provide this for you. 您可以在此处找到MPXJ的API文档,如果您的IDE没有为您提供的话,这些文档将使您大致了解每个对象上可用的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM