Exemple #1
0
 public static bool IsChineseNumeral(char ch)
 {
     if (NumeralUtil.IsArabicNumeral(ch))
     {
         return(false);
     }
     if (CharacterUtil.IsLantingLetter(ch))
     {
         return(false);
     }
     for (int j = 0; j < chnGenText.Length; j++)
     {
         if (ch == chnGenText[j] || ch == chnRMBText[j] || ch == chnFullCharText[j])
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #2
0
        public static bool IsCJKNumber(char ch)
        {
            for (int i = 0; i < chnGenText.Length; i++)
            {
                if (ch == chnGenText[i])
                {
                    return(true);
                }
            }

            if (NumeralUtil.IsArabicNumeral(ch))
            {
                return(true);
            }

            for (int i = 0; i < chnRMBText.Length; i++)
            {
                if (ch == chnRMBText[i])
                {
                    return(true);
                }
            }
            return(false);
        }
Exemple #3
0
        public static string ConvertChineseText2DateText(string text, string formatPattern)
        {
            string errText = "err";

            text = NumeralUtil.ConvertChineseNumeral2Arabic(text);
            char[]        chars         = text.ToCharArray();
            StringBuilder sbDateText    = new StringBuilder();
            StringBuilder sbPatternText = new StringBuilder();
            StringBuilder sbText        = new StringBuilder();
            int           strLen        = 0;

            for (int i = 0; i < text.Length; i++)
            {
                char ch = text[i];

                if (NumeralUtil.IsArabicNumeral(ch))
                {
                    sbDateText.Append(ch);
                    strLen++;
                }
                else if (ch == '年')
                {
                    sbDateText.Append(ch);
                    sbPatternText.Append(GeneratePatternText('y', strLen));
                    sbPatternText.Append(ch);
                    strLen = 0;
                }
                else if (ch == '日')
                {
                    sbDateText.Append(ch);
                    sbPatternText.Append(GeneratePatternText('d', strLen));
                    sbPatternText.Append(ch);
                    strLen = 0;
                }
                else if (ch == '月')
                {
                    sbDateText.Append(ch);
                    sbPatternText.Append(GeneratePatternText('M', strLen));
                    sbPatternText.Append(ch);
                    strLen = 0;
                }
                else if (ch == '分')
                {
                    sbDateText.Append(ch);
                    sbPatternText.Append(GeneratePatternText('m', strLen));
                    sbPatternText.Append(ch);
                    strLen = 0;
                }
                else if (ch == '秒')
                {
                    sbDateText.Append(ch);
                    sbPatternText.Append(GeneratePatternText('s', strLen));
                    sbPatternText.Append(ch);
                    strLen = 0;
                }
                else if (ch == '点')
                {
                    sbDateText.Append(ch);
                    sbPatternText.Append(GeneratePatternText('h', strLen));
                    sbPatternText.Append(ch);
                    strLen = 0;
                }
                else if (ch == '/')
                {
                    if (strLen == 4)
                    {
                        sbPatternText.Append(GeneratePatternText('y', strLen));
                    }
                    else if (strLen == 2)
                    {
                        sbPatternText.Append(GeneratePatternText('M', strLen));
                    }
                    sbPatternText.Append(ch);
                    sbDateText.Append(ch);
                    strLen = 0;
                }
                else if (ch == ' ')
                {
                    if (strLen == 2)
                    {
                        if (sbPatternText.ToString().IndexOf('M') >= 0)
                        {
                            sbPatternText.Append(GeneratePatternText('d', strLen));
                        }
                        else
                        {
                            sbPatternText.Append(GeneratePatternText('M', strLen));
                        }
                    }
                    continue;
                }
                else
                {
                    if (sbDateText.Length == 0)
                    {
                        sbText.Append(ch);
                        strLen = 0;
                        continue;
                    }
                    DateTime?dt = ParseDate(sbDateText.ToString(), sbPatternText.ToString());
                    if (dt != null)
                    {
                        sbText.AppendFormat(formatPattern == null?"[{0}]":"[{0:" + formatPattern + "}]", dt);
                    }
                    else
                    {
                        sbText.AppendFormat("[{0}]", errText);
                    }
                    //clear the string builder
                    sbDateText    = new StringBuilder();
                    sbPatternText = new StringBuilder();
                    sbText.Append(ch);
                    strLen = 0;
                    continue;
                }
            }
            if (sbDateText.Length != 0)
            {
                DateTime?dt = ParseDate(sbDateText.ToString(), sbPatternText.ToString());
                if (dt != null)
                {
                    sbText.AppendFormat(formatPattern == null ? "[{0}]" : "[{0:" + formatPattern + "}]", dt);
                }
                else
                {
                    sbText.AppendFormat("[{0}]", errText);
                }
            }
            return(sbText.ToString());
        }
Exemple #4
0
 public static bool IsUrlCharacter(char ch)
 {
     return(NumeralUtil.IsArabicNumeral(ch) || IsLantingLetter(ch) || ch == '_' || ch == '-');
 }