【问题标题】:String comparison not working for sharepoint multiline text values字符串比较不适用于共享点多行文本值
【发布时间】:2016-12-15 09:30:52
【问题描述】:

我正在从多行列的共享点列表中获取数据。 然后按空格分割数据并将其与其他字符串进行比较,但尽管两个字符串中的值相同,但它给出了错误的结果。

请按照以下代码:

    string[] strBodys = SPHttpUtility.ConvertSimpleHtmlToText(Convert.ToString(workflowProperties.ListItem[SCMSConstants.lstfldBody]), Convert.ToString(workflowProperties.ListItem[SCMSConstants.lstfldBody]).Length).Split(' ');

bool hasKwrdInBody = false;
foreach (SPItem oItem in oColl)
                        {//get all the keywords
                            string[] strkeyWrds = SPHttpUtility.ConvertSimpleHtmlToText(Convert.ToString(oItem[SCMSConstants.lstfldKWConfigKeywordsIntrName]), Convert.ToString(oItem[SCMSConstants.lstfldKWConfigKeywordsIntrName]).Length).Split(',');
//in body
                            foreach (string strKW in strkeyWrds)
                            {
                                string KWValue = strKW.Trim(' ').ToLower();
                                foreach (string strBdy in strBodys)
                                {
                                    string BodyValue = strBdy.Trim(' ').ToLower();
                                    //if (strKW.ToLower().Equals(strBdy.ToLower()))
                                    if(KWValue == BodyValue) //here it always gives false result
                                    {
                                        hasKwrdInBody = true;
                                        break;
                                    }
                                }
                                if (hasKwrdInBody)
                                    break;
                            }

                            if (!hasKwrdInSbjct && !hasKwrdInBody)
                            {
                                continue;
                            }
                            else
                            {
                                //set business unit to current groups rule
                                bsnsUnitLookupFld = new SPFieldLookupValue(Convert.ToString(oItem[SCMSConstants.lstfldBsnsUnit]));                                
                                asgndTo = new SPFieldUserValue(objWeb,Convert.ToString(oItem[SCMSConstants.lstfldKWConfigAssignedToIntrName])).User;
                                groupName = Convert.ToString(oItem[SCMSConstants.lstfldKWConfigAssignedToGroupIntrName]).Split('#').Last();
                                break;
                            }
}

请注意我正在尝试从共享点列表中获取多行文本 请提供您的建议。

【问题讨论】:

    标签: sharepoint multilinestring


    【解决方案1】:

    这还取决于您的多行字段的确切类型(例如纯文本或富文本等)。 如果您只是添加一些记录并写出您正在比较的值,也许会很清楚。

    有关如何获取多行文本字段值的详细信息,请查看Accessing Multiple line of text programmaticallyhere for RichText

    【讨论】:

      【解决方案2】:

      我通过比较和计算两个字符串中的字符来实现它。实际上,字符串中嵌入了一些 UTC 代码。首先,我使用正则表达式删除了这些字符,然后对它们进行了比较,它就像一个魅力。

      这是sn-p的代码,可能对一些人有帮助。

      string[] strBodys = SPHttpUtility.ConvertSimpleHtmlToText(Convert.ToString(workflowProperties.ListItem[SCMSConstants.lstfldBody]), Convert.ToString(workflowProperties.ListItem[SCMSConstants.lstfldBody]).Length).Split(' ');
      
      bool hasKwrdInBody = false;
      foreach (SPItem oItem in oColl)
                              {//get all the keywords
                                  string[] strkeyWrds = SPHttpUtility.ConvertSimpleHtmlToText(Convert.ToString(oItem[SCMSConstants.lstfldKWConfigKeywordsIntrName]), Convert.ToString(oItem[SCMSConstants.lstfldKWConfigKeywordsIntrName]).Length).Split(',');
      //in body
                                  foreach (string strKW in strkeyWrds)
                                  {
                                      string KWValue = strKW.Trim(' ').ToLower();
      KWValue = Regex.Replace(KWValue, @"[^\u0000-\u007F]", string.Empty); //here replaced the utc codes
                                      foreach (string strBdy in strBodys)
                                      {
                                          string BodyValue = strBdy.Trim(' ').ToLower();
      
       BodyValue = Regex.Replace(BodyValue, @"\t|\n|\r", string.Empty); // new code to replace utc code
                                                      BodyValue = Regex.Replace(BodyValue, @"[^\u0000-\u007F]", string.Empty); //new code to replace utc code
      
                                          //if (strKW.ToLower().Equals(strBdy.ToLower()))
                                          if(KWValue == BodyValue) //here it always gives false result
                                          {
                                              hasKwrdInBody = true;
                                              break;
                                          }
                                      }
                                      if (hasKwrdInBody)
                                          break;
                                  }
      
                                  if (!hasKwrdInSbjct && !hasKwrdInBody)
                                  {
                                      continue;
                                  }
                                  else
                                  {
                                      //set business unit to current groups rule
                                      bsnsUnitLookupFld = new SPFieldLookupValue(Convert.ToString(oItem[SCMSConstants.lstfldBsnsUnit]));                                
                                      asgndTo = new SPFieldUserValue(objWeb,Convert.ToString(oItem[SCMSConstants.lstfldKWConfigAssignedToIntrName])).User;
                                      groupName = Convert.ToString(oItem[SCMSConstants.lstfldKWConfigAssignedToGroupIntrName]).Split('#').Last();
                                      break;
                                  }
      }
      

      【讨论】:

        猜你喜欢
        • 2015-06-17
        • 1970-01-01
        • 1970-01-01
        • 2019-09-20
        • 1970-01-01
        • 1970-01-01
        • 2013-05-21
        • 1970-01-01
        相关资源
        最近更新 更多