0

I have a field named Responsibility in a user profile on sharepoint site which contains value like "abc; def; ghi". I want to read these values into an array. When i am using [propertyconstants.responsibility].value only abc is being read. How to read abc, def and ghi separately?

My code is:

string xpUser = up[PropertyConstants.Responsibility].Value.ToString();
string[] expUser = xpUser.Split(';');
4

3 回答 3

0

我假设你有这样的东西

string xpUser =  "abc; def; ghi";

你想要 abe, def & ghi 分别然后这样做

string[] arrayUser = xpUser.Split(';');
foreach(string user in arrayUser)
{
   //Do what you want with **user** , now this user will have values that you want 1 by 1
   //if you see the value of user, 1st time you will get abc, 2nd time def , 3rd time ghi
}
于 2013-03-22T05:17:10.313 回答
0

你的回答似乎暗示你想用标记“;”分割(因为你说你想要“abc”而不是“abc”)

这是一个演示这样做的单元测试。

 [Test]
 public void SplitStringByString()
 {
    string input = "abc; def; ghi";
    string[] expected = new[] {"abc", "def", "ghi"};

    var result = input.Split(new [] { "; " }, StringSplitOptions.None);

    Assert.That(result, Is.EquivalentTo(expected));
 }
于 2013-03-22T05:19:46.853 回答
0

感谢大家的帮助。

我终于能够找到解决方案

 var strUser = up.GetProfileValueCollection(PropertyConstants.Responsibility);
于 2013-03-22T05:46:03.593 回答