Пример #1
0
        // replace punctuation with space in a string
        public static string ReplacePuncWithSpaceThenTrim(string inTerm)
        {
            char[] temp = inTerm.ToCharArray();
            for (int i = 0; i < temp.Length; i++)
            {
                if (CharUtil.IsPunctuation(temp[i]) == true)
                {
                    temp[i] = ' ';
                }
            }
            string @out = Trim(new string(temp));

            return(@out);
        }
Пример #2
0
        // strip leading chars if it is a punctuation
        public static string StripLeadPuncSpace(string inTerm)
        {
            string outStrLead = inTerm;
            int    index      = 0;

            while ((index < outStrLead.Length) && ((CharUtil.IsPunctuation(outStrLead[index]) == true) || (outStrLead[index] == ' ')))
            {
                index++;
            }
            if ((index > 0) && (index < outStrLead.Length))
            {
                outStrLead = outStrLead.Substring(index);
            }
            return(outStrLead);
        }
Пример #3
0
        // strip ending chars if it is a punctuation
        public static string StripEndPuncSpace(string inTerm)
        {
            string outStrEnd = inTerm;
            int    length    = outStrEnd.Length;
            int    index     = length - 1;

            while ((index > -1) && ((CharUtil.IsPunctuation(outStrEnd[index]) == true) || (outStrEnd[index] == ' ')))
            {
                index--;
            }
            if ((index < length - 1) && (index > -1))
            {
                outStrEnd = outStrEnd.Substring(0, index + 1);
            }
            return(outStrEnd);
        }
Пример #4
0
        // strip punctuaction, then trim
        public static string StripPunctuation(string inTerm)
        {
            int length = inTerm.Length;

            char[] temp  = new char[length];
            int    index = 0;

            for (int i = 0; i < length; i++)
            {
                char tempChar = inTerm[i];
                if (CharUtil.IsPunctuation(tempChar) == false)
                {
                    temp[index] = tempChar;
                    index++;
                }
            }
            string @out = new string(temp);

            return(@out.Trim(new char[] { ' ', '\x00' }));            // must be trimmed
        }