0

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

请遵循以下代码:

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

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

4

2 回答 2

0

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

有关如何获取多行文本字段值的详细信息,请检查以编程方式访问多行文本 ,并在此处查看 RichText

于 2016-08-12T08:37:07.517 回答
0

我通过比较和计算两个字符串中的字符来让它工作。实际上,字符串中嵌入了一些 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;
                            }
}
于 2016-09-09T13:11:20.980 回答