字符串比较不适用于 Sharepoint 多行文本值

String comparison not working for sharepoint multiline text values

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

请关注以下代码:

    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;
                            }
}

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

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

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

我通过比较和计算两个字符串中的字符来让它工作。实际上,字符串中嵌入了一些 UTC 代码。首先,我使用正则表达式删除了这些字符,然后对它们进行了比较,效果非常好。

这是代码片段,可能会对某些人有所帮助。

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;
                            }
}