如何读取sharepoint用户配置文件中以分号分隔的值

本文关键字:分隔 配置文件 用户 何读取 读取 sharepoint | 更新日期: 2023-09-27 18:05:28

我在sharepoint网站的用户配置文件中有一个名为Responsibility的字段,其中包含像"abc;能延期的;全球健康行动计划"。我想把这些值读入一个数组。当我使用[propertyconstants.responsibility]时。只有ABC值正在被读取。如何分别阅读abc, def和hi ?

我的代码是:
string xpUser = up[PropertyConstants.Responsibility].Value.ToString();
string[] expUser = xpUser.Split(';');

如何读取sharepoint用户配置文件中以分号分隔的值

我假设这里有这样的内容

string xpUser =  "abc; def; ghi";

你想要abe, def &然后单独执行

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
}

您的回答似乎暗示您要按令牌"分割;(因为你说你想要"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));
 }

感谢大家的帮助。

我终于找到了解决方案

 var strUser = up.GetProfileValueCollection(PropertyConstants.Responsibility);