Trim() публичный статический Метод

Trim off leading space
public static Trim ( string s ) : string
s string
Результат string
Пример #1
0
        /// <summary>Process a line of input.</summary>
        /// <remarks>Process a line of input.</remarks>
        public virtual string ProcessInput(string s)
        {
            string reply;

            // Do some input transformations first.
            s = EString.Translate(s, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz"
                                  );
            s = EString.Translate(s, "@#$%^&*()_-+=~`{[}]|:;<>\\\"", "                          "
                                  );
            s = EString.Translate(s, ",?!", "...");
            // Compress out multiple speace.
            s = EString.Compress(s);
            string[] lines = new string[2];
            // Break apart sentences, and do each separately.
            while (EString.Match(s, "*.*", lines))
            {
                reply = Sentence(lines[0]);
                if (reply != null)
                {
                    return(reply);
                }
                s = EString.Trim(lines[1]);
            }
            if (s.Length != 0)
            {
                reply = Sentence(s);
                if (reply != null)
                {
                    return(reply);
                }
            }
            // Nothing matched, so try memory.
            string m = mem.Get();

            if (m != null)
            {
                return(m);
            }
            // No memory, reply with xnone.
            Key key = keys.GetKey("xnone");

            if (key != null)
            {
                Key dummy = null;
                reply = Decompose(key, s, dummy);
                if (reply != null)
                {
                    return(reply);
                }
            }
            // No xnone, just say anything.
            return("I am at a loss for words.");
        }
Пример #2
0
        /// <summary>Translate a string s.</summary>
        /// <remarks>
        /// Translate a string s.
        /// (1) Trim spaces off.
        /// (2) Break s into words.
        /// (3) For each word, substitute matching src word with dest.
        /// </remarks>
        public virtual string Translate(string s)
        {
            string[] lines = new string[2];
            string   work  = EString.Trim(s);

            s = string.Empty;
            while (EString.Match(work, "* *", lines))
            {
                s   += Xlate(lines[0]) + " ";
                work = EString.Trim(lines[1]);
            }
            s += Xlate(work);
            return(s);
        }
Пример #3
0
        /// <summary>Break the string s into words.</summary>
        /// <remarks>
        /// Break the string s into words.
        /// For each word, if isKey is true, then push the key
        /// into the stack.
        /// </remarks>
        public virtual void BuildKeyStack(KeyStack stack, string s)
        {
            stack.Reset();
            s = EString.Trim(s);
            string[] lines = new string[2];
            Key      k;

            while (EString.Match(s, "* *", lines))
            {
                k = GetKey(lines[0]);
                if (k != null)
                {
                    stack.PushKey(k);
                }
                s = lines[1];
            }
            k = GetKey(s);
            if (k != null)
            {
                stack.PushKey(k);
            }
        }