コード例 #1
0
        /// <summary>
        /// Creates a new CharacterString containing a substring of this one.
        /// </summary>
        /// <param name="startIndex">The zero-based starting character position of the
        /// substring in this instance</param>
        /// <param name="length">The number of characters in the substring.</param>
        /// <returns>A new CharacterString containing the substring.</returns>
        public CharacterString Substring(int startIndex, int length)
        {
            CharacterString substring = new CharacterString();

            substring.AddRange(this.Where((c, index) => (index >= startIndex) && (index < startIndex + length)));

            return(substring);
        }
コード例 #2
0
        /// <summary>
        /// Removes all leading and trailing whitespace from this CharacterString. This
        /// CharacterString is not affected.
        /// </summary>
        /// <returns>The trimmed CharacterString.</returns>
        public CharacterString Trim()
        {
            CharacterString trimmed = new CharacterString(this);

            // trim from the front
            while ((trimmed.Count > 0) && (trimmed[0].IsWhitespace))
            {
                trimmed.RemoveAt(0);
            }

            // trim from the end
            while ((trimmed.Count > 0) && (trimmed[trimmed.Count - 1].IsWhitespace))
            {
                trimmed.RemoveAt(trimmed.Count - 1);
            }

            return(trimmed);
        }
コード例 #3
0
        public void Write(CharacterString text)
        {
            Vec pos = Vec.Zero;

            CheckBounds(pos.X, pos.Y);

            foreach (Character c in text)
            {
                Set(pos, c);
                pos += new Vec(1, 0);

                // don't run past edge
                if (pos.X >= Size.X)
                {
                    break;
                }
            }
        }