コード例 #1
0
ファイル: DSUtil.cs プロジェクト: weidnerk/dsutil
        /// <summary>
        /// Red flag if supplier item description contains certain key words.
        /// Hard-coding for now - let's see where this goes.
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static bool ContationsKeyWords(string str, out List <string> help)
        {
            help = new List <string>();
            bool ret = false;

            if (string.IsNullOrEmpty(str))
            {
                return(false);
            }
            string justText = DSUtil.HTMLToString_Full(str);
            int    pos      = justText.ToUpper().IndexOf("COMMENTS");

            if (pos > -1)
            {
                help.Add("contains COMMENTS");
                ret = true;
            }
            pos = justText.ToUpper().IndexOf("INTERACTIVE TOUR");
            if (pos > -1)
            {
                help.Add("contains INTERACTIVE TOUR");
                ret = true;
            }
            pos = justText.ToUpper().IndexOf("QUESTIONS");
            if (pos > -1)
            {
                help.Add("contains QUESTIONS");
                ret = true;
            }
            pos = justText.ToUpper().IndexOf("WALMART");
            if (pos > -1)
            {
                help.Add("contains WALMART");
                ret = true;
            }
            pos = justText.ToUpper().IndexOf("WARRANTY");
            if (pos > -1)
            {
                help.Add("contains WARRANTY");
                ret = true;
            }
            pos = justText.ToUpper().IndexOf("PACK");
            if (pos > -1)
            {
                help.Add("contains PACK");
                ret = true;
            }
            pos = justText.ToUpper().IndexOf("WARNING");
            if (pos > -1)
            {
                help.Add("contains WARNING");
                ret = true;
            }
            pos = justText.ToUpper().IndexOf("VIRTUAL TOUR");
            if (pos > -1)
            {
                help.Add("contains VIRTUAL TOUR");
                ret = true;
            }
            pos = justText.ToUpper().IndexOf("CUSTOMER SERVICE");
            if (pos > -1)
            {
                help.Add("contains CUSTOMER SERVICE");
                ret = true;
            }
            pos = justText.ToUpper().IndexOf("RECALL");
            if (pos > -1)
            {
                help.Add("contains RECALL");
                ret = true;
            }
            pos = justText.ToUpper().IndexOf("SEE OUR");
            if (pos > -1)
            {
                help.Add("contains SEE OUR");
                ret = true;
            }
            pos = justText.ToUpper().IndexOf("SHIPPING");
            if (pos > -1)
            {
                help.Add("contains SHIPPING");
                ret = true;
            }
            pos = justText.ToUpper().IndexOf("RETURNS");
            if (pos > -1)
            {
                help.Add("contains RETURNS");
                ret = true;
            }
            pos = justText.ToUpper().IndexOf("AVAILABLE");
            if (pos > -1)
            {
                help.Add("contains AVAILABLE");
                ret = true;
            }
            pos = justText.ToUpper().IndexOf("MULTIPLE SIZES");
            if (pos > -1)
            {
                help.Add("contains MULTIPLE SIZES");
                ret = true;
            }
            pos = justText.ToUpper().IndexOf("MULTIPLE COLORS");
            if (pos > -1)
            {
                help.Add("contains MULTIPLE COLORS");
                ret = true;
            }

            pos = justText.ToUpper().IndexOf("AVAILABLE COLORS");
            if (pos > -1)
            {
                help.Add("contains AVAILABLE COLORS");
                ret = true;
            }
            pos = justText.ToUpper().IndexOf("AVAILABLE SIZES");
            if (pos > -1)
            {
                help.Add("contains AVAILABLE SIZES");
                ret = true;
            }
            pos = justText.ToUpper().IndexOf("SEE MORE");
            if (pos > -1)
            {
                help.Add("contains SEE MORE");
                ret = true;
            }
            pos = justText.ToUpper().IndexOf("CHOKING HAZARD");
            if (pos > -1)
            {
                help.Add("contains CHOKING HAZARD");
                ret = true;
            }
            pos = justText.ToUpper().IndexOf("THIS TOY IS NOT SUITABLE");
            if (pos > -1)
            {
                help.Add("contains THIS TOY IS NOT SUITABLE");
                ret = true;
            }

            pos = justText.ToUpper().IndexOf("?");
            if (pos > -1)
            {
                help.Add("contains ?");
                ret = true;
            }
            return(ret);
        }
コード例 #2
0
ファイル: DSUtil.cs プロジェクト: weidnerk/dsutil
        /// <summary>
        /// Probably should put this in walmart library - they have funny habit of placing question marks in odd places.
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static bool ContainsQuestionMark(string str, out string segment)
        {
            const string marker        = "&#39;";
            const int    segmentLength = 10;

            segment = null;
            bool fail = false;
            bool done = false;
            int  pos  = 0;

            if (string.IsNullOrEmpty(str))
            {
                return(false);
            }
            string justText = DSUtil.HTMLToString_Full(str);

            do
            {
                pos = justText.IndexOf(marker, pos);
                if (pos > -1)
                {
                    if (pos < justText.Length)
                    {
                        // BUG here - need to check that (pos + marker.Length <= justText.len)
                        char c = justText[pos + marker.Length];
                        fail = Char.IsLetterOrDigit(c);
                        if (fail)
                        {
                            // get segment that contains the question mark
                            if (pos > segmentLength)
                            {
                                segment = justText.Substring(pos - segmentLength, segmentLength);
                            }
                            else
                            {
                                segment = justText.Substring(0, pos);
                            }
                            if (pos + segmentLength < justText.Length)
                            {
                                var endSegment = justText.Substring(pos, segmentLength);
                                segment += endSegment;
                            }
                            else
                            {
                                segment += justText.Substring(pos, 1);
                            }
                            done = true;
                        }
                        else
                        {
                            pos += 2;
                        }
                    }
                    else
                    {
                        done = true;
                    }
                }
                else
                {
                    done = true;
                }
            } while (!done);
            return(fail);
        }