2016-08-09 2 views
0

Я извлекаю данные из списка sharepoint для многострочного столбца. Затем разделите данные по пробелам и сравните их с другой строкой, но, несмотря на то, что значение в обеих строках одинаково, дает ложный результат.Сравнение строк не работает для многострочных текстовых значений sharepoint

Пожалуйста, следуйте ниже код:

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 Просьба представить свои предложения.

ответ

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

Это также зависит от конкретного типа вашего многострочного поля (например, обычного текста или RichText и т. Д.). Возможно, было бы ясно, если бы вы просто добавили некоторые записи, выписывая значения, которые вы сравниваете.

Для получения дополнительной информации о том, как получить значение Multiline проверки текстового поля Accessing Multiple line of text programmatically и here for RichText

Смежные вопросы