public void TriemEndTest()
 {
     StringBuilder sb;
     sb = new StringBuilder("asdfgef");
     Assert.Equal(sb.TrimEnd('a').ToString(), "asdfgef");
     Assert.Equal(sb.TrimEnd('f').ToString(), "asdfge");
     sb.Append("   ");
     Assert.Equal(sb.TrimEnd().ToString(), "asdfge");
     Assert.Equal(sb.TrimEnd(new[] { 'g', 'e' }).ToString(), "asdf");
     Assert.Equal(sb.TrimEnd("asdf").ToString(), string.Empty);
 }
Example #2
0
    internal string ToString(string sufix)
    {
        StringBuilder info = new StringBuilder();

        info.AppendFormat("Name: {0} {1}", this.FirstName, this.LastName).AppendLine();
        info.AppendLine(sufix).Replace(Environment.NewLine, Environment.NewLine + SuffixIndentation);
        return info.TrimEnd().ToString();
    }
Example #3
0
    public override string ToString()
    {
        StringBuilder info = new StringBuilder();

        info.AppendLine("# School: " + this.Name);
        info.AppendLine(this.classes.ToString<Class>());

        return info.TrimEnd().ToString();
    }
Example #4
0
    public override string ToString()
    {
        StringBuilder info = new StringBuilder();

        info.AppendLine(base.ToString());

        info.AppendLine(this.disciplines.ToString<Discipline>());

        return info.TrimEnd().ToString();
    }
        public override string ToString()
        {
            if (string.IsNullOrEmpty(TableName))
                throw new ArgumentException("TableName must be set.");

            var sb = new StringBuilder("INSERT INTO ");
            AddTableInfo(sb, SchemaName, TableName);
            sb.Append(" (");

            Columns.ForEach(c => sb.AppendFormat(QUOTE_FORMAT, c).Append(","));
            sb.TrimEnd(',');

            sb.Append(") VALUES (");
            Columns.ForEach(c => sb.AppendFormat(PARAM_FORMAT, c).Append(","));
            sb.TrimEnd(',');

            sb.Append(")");

            return sb.ToString();
        }
        public void Process(
            XmlReader xmlReader, 
            StringBuilder output,
            ElementProcessContext elementProcessContext)
        {
            if (elementProcessContext.Current.IsPreservingSpace)
            {
                output.Append("</").Append(xmlReader.Name).Append(">");
            }
            else if (elementProcessContext.Current.IsSignificantWhiteSpace && !output.IsNewLine())
            {
                output.Append("</").Append(xmlReader.Name).Append(">");
            }
            else if ((elementProcessContext.Current.ContentType == ContentTypeEnum.None)
                && this.options.RemoveEndingTagOfEmptyElement)
            {
                // Shrink the current element, if it has no content.
                // E.g., <Element>  </Element> => <Element />
                output = output.TrimEnd(' ', '\t', '\r', '\n');

                int bracketIndex = output.LastIndexOf('>');
                output.Insert(bracketIndex, '/');

                if ((output[bracketIndex - 1] != '\t') 
                    && (output[bracketIndex - 1] != ' ')
                    && this.options.SpaceBeforeClosingSlash)
                {
                    output.Insert(bracketIndex, ' ');
                }
            }
            else if ((elementProcessContext.Current.ContentType == ContentTypeEnum.SingleLineTextOnly)
                && !elementProcessContext.Current.IsMultlineStartTag)
            {
                int bracketIndex = output.LastIndexOf('>');

                string text = output.Substring((bracketIndex + 1), (output.Length - bracketIndex - 1)).Trim();

                output.Length = (bracketIndex + 1);
                output.Append(text).Append("</").Append(xmlReader.Name).Append(">");
            }
            else
            {
                string currentIndentString = this.indentService.GetIndentString(xmlReader.Depth);

                if (!output.IsNewLine())
                {
                    output.Append(Environment.NewLine);
                }

                output.Append(currentIndentString).Append("</").Append(xmlReader.Name).Append(">");
            }

            elementProcessContext.Pop();
        }
Example #7
0
        protected string ToString(string suffix)
        {
            StringBuilder info = new StringBuilder();

            info.AppendFormat("Name: {0} {1}", this.firstName, this.lastName).AppendLine();

            info.AppendLine(suffix).Replace(
                Environment.NewLine, Environment.NewLine
            );

            return info.TrimEnd().ToString();
        }
        public void Process(XmlReader xmlReader, StringBuilder output, ElementProcessContext elementProcessContext)
        {
            if (elementProcessContext.Current.IsPreservingSpace)
            {
                output.Append("</").Append(xmlReader.Name).Append(">");
            }
            else if (elementProcessContext.Current.IsSignificantWhiteSpace && !output.IsNewLine())
            {
                output.Append("</").Append(xmlReader.Name).Append(">");
            }
            // Shrink the current element, if it has no content.
            // E.g., <Element>  </Element> => <Element />
            else if (elementProcessContext.Current.ContentType == ContentTypeEnum.NONE && _options.RemoveEndingTagOfEmptyElement)
            {
                #region shrink element with no content

                output = output.TrimEnd(' ', '\t', '\r', '\n');

                int bracketIndex = output.LastIndexOf('>');
                output.Insert(bracketIndex, '/');

                if (output[bracketIndex - 1] != '\t' && output[bracketIndex - 1] != ' ' && _options.SpaceBeforeClosingSlash)
                {
                    output.Insert(bracketIndex, ' ');
                }

                #endregion shrink element with no content
            }
            else if (elementProcessContext.Current.ContentType == ContentTypeEnum.SINGLE_LINE_TEXT_ONLY && elementProcessContext.Current.IsMultlineStartTag == false)
            {
                int bracketIndex = output.LastIndexOf('>');

                string text = output.Substring(bracketIndex + 1, output.Length - bracketIndex - 1).Trim();

                output.Length = bracketIndex + 1;
                output.Append(text).Append("</").Append(xmlReader.Name).Append(">");
            }
            else
            {
                string currentIndentString = _indentService.GetIndentString(xmlReader.Depth);

                if (!output.IsNewLine())
                {
                    output.Append(Environment.NewLine);
                }

                output.Append(currentIndentString).Append("</").Append(xmlReader.Name).Append(">");
            }

            elementProcessContext.Pop();
        }
Example #9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                DataEntities ent = new DataEntities();

                long chapterid = WS.RequestString("cid").ToInt64();
                BookChapter bc = (from l in ent.BookChapter where l.ID == chapterid select l).FirstOrDefault();
                bc.ClickCount = bc.ClickCount > 0 ? bc.ClickCount + 1 : 1;

                ent.SaveChanges();

                ent.Dispose();
                //写入Cookie

                List<Cook> cookies = new List<Cook>();
                if (Voodoo.Cookies.Cookies.GetCookie("history") != null)
                {
                    string[] chapters = Voodoo.Cookies.Cookies.GetCookie("history").Value.Split(',');
                    foreach (string chapter in chapters)
                    {
                        string[] arr_chapter = chapter.Split('|');
                        cookies.Add(new Cook() { id = arr_chapter[0].ToInt64(), time = arr_chapter[1].ToDateTime(), bookid = arr_chapter[2].ToInt32() });
                    }
                }

                cookies = cookies.Where(p => p.bookid != bc.BookID).OrderByDescending(p => p.time).Take(4).ToList();
                cookies.Add(new Cook() { id = chapterid, time = DateTime.Now, bookid=bc.BookID });

                StringBuilder sb = new StringBuilder();

                foreach (Cook c in cookies)
                {
                    sb.Append(string.Format("{0}|{1}|{2},", c.id, c.time.ToString(), c.bookid.ToS()));
                }
                sb = sb.TrimEnd(',');

                HttpCookie _cookie = new HttpCookie("history", sb.ToString());
                _cookie.Expires = DateTime.Now.AddYears(1);

                Voodoo.Cookies.Cookies.SetCookie(_cookie);
            }//end try
            catch
            {
                Voodoo.Cookies.Cookies.Remove("history");
            }
        }
        public override string ToString()
        {
            if (string.IsNullOrEmpty(TableName))
                throw new ArgumentException("TableName must be set.");

            var sb = new StringBuilder("UPDATE ");
            AddTableInfo(sb, SchemaName, TableName);
            sb.Append(" SET ");

            Columns.IterateOver((i, c) => sb.AppendFormat(UPDATE_FORMAT, c).Append(","));
            sb.TrimEnd(',');

            whereHelper.ClauseBuilder = sb;
            whereHelper.AppendWhere();

            return sb.ToString();
        }
Example #11
0
        private string InnerSerialize(CfgNode node) {
            var meta = CfgMetadataCache.GetMetadata(node.GetType());
            var builder = new StringBuilder();
            if (meta.All(kv => kv.Value.ListType == null)) {
                builder.Append("{");
                SerializeAttributes(meta, node, builder);
                builder.TrimEnd(", ");
                builder.Append(" }");
            } else {
                builder.AppendLine("{");
                SerializeAttributes(meta, node, builder);
                SerializeElements(meta, node, builder, 1);
                builder.AppendLine();
                builder.Append("}");
            }

            return builder.ToString();
        }
Example #12
0
 private static void Next(StringBuilder sb, int i, int last) {
     if (i < last) {
         sb.TrimEnd(", ");
         sb.Append(" }");
         sb.AppendLine(",");
     } else {
         sb.TrimEnd(", ");
         sb.AppendLine(" }");
     }
 }
Example #13
0
        /// <summary>
        /// 友情链接
        /// </summary>
        /// <returns></returns>
        public static string getlink(string n)
        {
            using (DataEntities ent = new DataEntities())
            {
                StringBuilder sb = new StringBuilder("");
                var links =// LinkView.GetModelList("id>0 order by [Index]");
                    (from l in ent.Link orderby l.Index select l).ToList();
                foreach (var l in links)
                {
                    sb.AppendLine(string.Format("<a href=\"{0}\" target=\"_blank\">{1}</a>|", l.Url, l.LinkTitle));
                }

                return sb.TrimEnd('|').ToString();
            }
        }
Example #14
0
        /// <summary>
        /// 轮播Flash
        /// </summary>
        /// <param name="ClassID"></param>
        /// <param name="count"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="showTitle"></param>
        /// <param name="titleLength"></param>
        /// <param name="interval"></param>
        /// <param name="ExtSql"></param>
        /// <param name="Order"></param>
        /// <returns></returns>
        public static string cmsflashpic(string ClassID, string count, string width, string height, string showTitle, string titleLength, string interval, string ExtSql, string Order)
        {
            DataEntities ent = new DataEntities();

            StringBuilder sb = new StringBuilder();
            sb.AppendLine("<!--开始FLASH-->");
            sb.AppendLine("<div class=\"flash\">");
            sb.AppendLine("<script type=\"text/javascript\">");
            sb.AppendLine("<!--");

            sb.AppendLine(string.Format("var interval_time={0};", interval));
            sb.AppendLine(string.Format("var focus_width={0};", width));
            sb.AppendLine(string.Format("var focus_height={0};", height));
            if (showTitle.ToInt32() > 0)
            {
                sb.AppendLine("var text_height=20;");
            }
            else
            {
                sb.AppendLine("var text_height=0;");
            }
            sb.AppendLine("var text_align=\"center\";");
            sb.AppendLine("var swf_height = focus_height+text_height;");
            sb.AppendLine("var swfpath=\"/e/data/images/pixviewer.swf\";");
            sb.AppendLine("var swfpatha=\"/e/data/images/pixviewer.swf\";");

            StringBuilder sb_pics = new StringBuilder();
            StringBuilder sb_links = new StringBuilder();
            StringBuilder sb_texts = new StringBuilder();

            #region 图片变量
            sb_pics.Append("var pics=\"");
            sb_links.Append("var links=\"");
            sb_texts.Append("var texts=\"");

            string str_sql = string.Format("(ZtID='{0}' or ClassID='{1}') and len(TitleImage)>0", ClassID, ClassID);
            if (ExtSql.Length > 0)
            {
                str_sql += " and " + ExtSql;
            }
            if (Order.Length > 0)
            {
                str_sql += " order by " + Order;
            }

            List<News> newses = //NewsView.GetModelList(str_sql, count.ToInt32());
                ent.CreateQuery<News>(string.Format("select top {0} * from News where {1}", count, str_sql)).ToList();

            newses = newses.Where(p => p.TitleImage.IndexOf(".gif") < 0).ToList();//不支持GIF文件
            foreach (News n in newses)
            {
                sb_pics.Append(n.TitleImage + "|");
                sb_links.Append(BasePage.GetNewsUrl(n, n.GetClass()) + "|");
                sb_texts.Append(n.Title.CutString(titleLength.ToInt32()) + "|");
            }
            sb_pics = sb_pics.TrimEnd('|');
            sb_links = sb_links.TrimEnd('|');
            sb_texts = sb_texts.TrimEnd('|');

            sb_pics.Append("\";\n");
            sb_links.Append("\";\n");
            sb_texts.Append("\";\n");

            sb.Append(sb_pics.ToString());
            sb.Append(sb_links.ToString());
            sb.Append(sb_texts.ToString());
            #endregion

            #region 输出Flash
            sb.AppendLine("document.write('<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"'+ focus_width +'\" height=\"'+ swf_height +'\">'); ");
            sb.AppendLine("document.write('<param name=\"movie\" value=\"'+swfpath+'\"><param name=\"quality\" value=\"high\"><param name=\"bgcolor\" value=\"#ffffff\">'); ");
            sb.AppendLine("document.write('<param name=\"menu\" value=\"false\"><param name=wmode value=\"opaque\">'); ");
            sb.AppendLine("document.write('<param name=\"FlashVars\" value=\"pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'&text_align='+text_align+'&interval_time='+interval_time+'\">'); ");
            sb.AppendLine("document.write('<embed src=\"'+swfpath+'\" wmode=\"opaque\" FlashVars=\"pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'&text_align='+text_align+'&interval_time='+interval_time+'\" menu=\"false\" bgcolor=\"#ffffff\" quality=\"high\" width=\"'+ focus_width +'\" height=\"'+ swf_height +'\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />');");
            sb.AppendLine("document.write('</object>');");
            #endregion

            sb.AppendLine("//-->");
            sb.AppendLine("</script>");
            sb.AppendLine("</div>");
            ent.Dispose();

            return sb.ToString();
        }
        /// <summary>
        /// 获取表的Sql脚本
        /// </summary>
        /// <param name="table"></param>
        /// <returns></returns>
        public override string GetTableSqlText(SOTable table)
        {
            List<SOColumn> columnnList = table.ColumnList;
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("create table [dbo].[" + table.Name + "] (");
            foreach(SOColumn item in columnnList)
            {
                sb.AppendFormat("\t[{0}] {1}", item.Name, item.NativeType);
                if (item.PrimaryKey)
                {
                    sb.Append(" PRIMARY KEY ");
                }

                if (item.Identify)
                {
                    sb.Append(" identity ");
                }
                else if (!item.Identify)
                {
                    sb.Append(" not null ");

                    if (item.DefaultValue != null && item.DefaultValue != "")
                    {
                        sb.Append(" default " + item.DefaultValue);
                    }
                }

                sb.Append(",\r\n");
            }

            sb = sb.TrimEnd(",\r\n");
            sb.AppendLine("\r\n)");
            return sb.ToString() ;
        }
Example #16
0
        private void ProcessEndElement(XmlReader xmlReader, StringBuilder output)
        {
            // Shrink the current element, if it has no content.
            // E.g., <Element>  </Element> => <Element />
            if (ContentTypeEnum.NONE == _elementProcessStatusStack.Peek().ContentType
                && Options.RemoveEndingTagOfEmptyElement)
            {
                #region shrink element with no content

                output = output.TrimEnd(' ', '\t', '\r', '\n');

                int bracketIndex = output.LastIndexOf('>');
                output.Insert(bracketIndex, '/');

                if (output[bracketIndex - 1] != '\t' && output[bracketIndex - 1] != ' ' && Options.SpaceBeforeClosingSlash)
                {
                    output.Insert(bracketIndex, ' ');
                }

                #endregion shrink element with no content
            }
            else if (ContentTypeEnum.SINGLE_LINE_TEXT_ONLY == _elementProcessStatusStack.Peek().ContentType
                     && false == _elementProcessStatusStack.Peek().IsMultlineStartTag)
            {
                int bracketIndex = output.LastIndexOf('>');

                string text = output.Substring(bracketIndex + 1, output.Length - bracketIndex - 1).Trim();

                output.Length = bracketIndex + 1;
                output.Append(text).Append("</").Append(xmlReader.Name).Append(">");
            }
            else
            {
                string currentIndentString = GetIndentString(xmlReader.Depth);

                if (!output.IsNewLine())
                {
                    output.Append(Environment.NewLine);
                }

                output.Append(currentIndentString).Append("</").Append(xmlReader.Name).Append(">");
            }
        }
        private void AddColumns(StringBuilder sb)
        {
            var pks = new List<Column>();

            Columns.ForEach(
                c =>
                    {
                        AddColumnDefinition(sb, c);
                        sb.AppendLine(",");

                        if (c.Property.Match(ColumnProperty.PrimaryKey))
                        {
                            pks.Add(c);
                        }
                    });

            if (0 != pks.Count)
            {
                var pksSb = new StringBuilder();
                pks.ForEach(c => pksSb.AppendFormat(PK_FORMAT, c.Name).AppendLine(","));
                pksSb.TrimEnd().TrimEnd(',');
                sb.AppendFormat(PK_BLOCK, pksSb).AppendLine();
            }

            sb.TrimEnd().TrimEnd(',');
        }
Example #18
0
        private void ProcessEndElement(XmlReader xmlReader, StringBuilder output)
        {
            if (this.ElementProcessStatusStack.Peek().IsPreservingSpace)
            {
                output.Append("</").Append(xmlReader.Name).Append(">");
            }
            else if (this.ElementProcessStatusStack.Peek().IsSignificantWhiteSpace && !output.IsNewLine())
            {
                output.Append("</").Append(xmlReader.Name).Append(">");
            }
            // Shrink the current element, if it has no content.
            // E.g., <Element>  </Element> => <Element />
            else if ((ContentTypeEnum.None == this.ElementProcessStatusStack.Peek().ContentType)
                && Options.RemoveEndingTagOfEmptyElement)
            {
                #region shrink element with no content

                output = output.TrimEnd(' ', '\t', '\r', '\n');

                int bracketIndex = output.LastIndexOf('>');
                output.Insert(bracketIndex, '/');

                if ((output[bracketIndex - 1] != '\t')
                    && (output[bracketIndex - 1] != ' ')
                    && Options.SpaceBeforeClosingSlash)
                {
                    output.Insert(bracketIndex, ' ');
                }

                #endregion shrink element with no content
            }
            else if ((ContentTypeEnum.SingleLineTextOnly == this.ElementProcessStatusStack.Peek().ContentType)
                && !this.ElementProcessStatusStack.Peek().IsMultlineStartTag)
            {
                int bracketIndex = output.LastIndexOf('>');

                string text = output.Substring(bracketIndex + 1, output.Length - bracketIndex - 1).Trim();

                output.Length = bracketIndex + 1;
                output.Append(text).Append("</").Append(xmlReader.Name).Append(">");
            }
            else
            {
                string currentIndentString = this.GetIndentString(xmlReader.Depth);

                if (!output.IsNewLine())
                {
                    output.Append(Environment.NewLine);
                }

                output.Append(currentIndentString).Append("</").Append(xmlReader.Name).Append(">");
            }
        }
        public override string ToString()
        {
            if (string.IsNullOrEmpty(TableName))
                throw new ArgumentException("TableName must be set.");

            var sb = new StringBuilder("SELECT ");
            if (0 == Columns.Count)
            {
                sb.Append("*");
            }
            else
            {
                Columns.ForEach(c => sb.Append(c).Append(","));
                sb.TrimEnd(',');
            }
            sb.Append(" FROM ");

            AddTableInfo(sb, SchemaName, TableName);

            whereHelper.ClauseBuilder = sb;
            whereHelper.AppendWhere();

            return sb.ToString();
        }