Ejemplo n.º 1
0
        public string replaceDomain(string str)
        {
            str = str.Replace(">", "> ").Replace("<", " <");
            var strSplitArr = str.Split(' ');

            List <int> tempIndex = new List <int>();

            for (int i = 0; i < strSplitArr.Length; i++)
            {
                string firstStrSplit = UnicodeUtil.removeVietnameseUnicode(strSplitArr[i].ToLower().Trim());
                if (firstStrSplit == "phim")
                {
                    tempIndex.Add(i);
                    while (UnicodeUtil.removeVietnameseUnicode(strSplitArr[++i].ToLower().Trim()) == "")
                    {
                        ;
                    }
                    string secondStrSplit = UnicodeUtil.removeVietnameseUnicode(strSplitArr[i].ToLower().Trim());
                    if (secondStrSplit == "bat")
                    {
                        tempIndex.Add(i);
                        while (UnicodeUtil.removeVietnameseUnicode(strSplitArr[++i].ToLower().Trim()) == "")
                        {
                            ;
                        }
                        string thirdStrSplit = UnicodeUtil.removeVietnameseUnicode(strSplitArr[i].ToLower().Trim());
                        if (thirdStrSplit == "hu")
                        {
                            strSplitArr[i] = meDomain;
                        }
                        else
                        {
                            tempIndex.RemoveAt(tempIndex.Count - 1);
                            tempIndex.RemoveAt(tempIndex.Count - 1);
                        }
                    }
                }
            }

            string[] strsNeedReplace = { "phimbathu", "bilutv" };
            for (int i = 0; i < strSplitArr.Length; i++)
            {
                string strSplit = UnicodeUtil.removeVietnameseUnicode(strSplitArr[i].ToLower()).Trim();
                foreach (var strNeedReplace in strsNeedReplace)
                {
                    if (strSplit.Trim().IndexOf(strNeedReplace) != -1 && strSplit.IndexOf("http") == -1)
                    {
                        strSplitArr[i] = strSplit.Replace(strNeedReplace, meDomainNoExt);
                        break;
                    }
                }
            }

            var rs = "";

            for (int i = 0; i < strSplitArr.Length; i++)
            {
                if (!tempIndex.Contains(i))
                {
                    rs += strSplitArr[i] + " ";
                }
            }
            return(rs.TrimEnd());
        }