如何用另一个字符替换行分隔符?

How to replace row delimiter character with another character?

这是我使用 FetchXml

从 Dynamics CRM 获取 "comment" 属性的行

属性名称="comment"

如果在评论属性中“/r/n”介于它们之间,如果我想用其他特殊字符替换它,我该如何用另一个替换“/r/n”,在 FetchXml 查询中?

您不能将 r/n/ 替换为 FetchXml 查询的一部分(这实际上意味着对数据库中的评论进行更新)。您首先检索记录,然后进行替换。

例如,假设您在帐户实体上有评论字段,那么(在服务器端):

string fetch = @"  
   <fetch version='1.0' mapping='logical' distinct='false'>  
     <entity name='account'>   
        <attribute name='comment'/>   
     </entity>   
   </fetch> ";   

EntityCollection result = _serviceProxy.RetrieveMultiple(new FetchExpression(fetch));
foreach (var account in result.Entities)
{
   // replace \r\n with a comma
   string comment = account.GetAttributeValue<string>("comment"); 
   if (!string.IsNullOrEmpty(comment))
   {
       var lines = comment.Split(new string[] { "\r\n" }, StringSplitOptions.None);
       Console.WriteLine(string.Join(",", lines)); 
   } 
}