本文整理汇总了C#中StringBuilder.RemoveLastChar方法的典型用法代码示例。如果您正苦于以下问题:C# StringBuilder.RemoveLastChar方法的具体用法?C# StringBuilder.RemoveLastChar怎么用?C# StringBuilder.RemoveLastChar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringBuilder
的用法示例。
在下文中一共展示了StringBuilder.RemoveLastChar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToJson
public override string ToJson()
{
var sb = new StringBuilder();
sb.Append("{");
foreach (var keyVP in props)
{
sb.Append(keyVP.Key.AsJavaScript() + ":");
if (keyVP.Value is JsBaseObject)
sb.Append(((JsBaseObject)keyVP.Value).ToJson() + ",");
else
sb.Append(Json.Encode(keyVP.Value) + ",");
}
foreach (var keyVP in rawProps)
{
sb.Append(keyVP.Key.AsJavaScript() + ":");
sb.Append(keyVP.Value + ",");
}
if (sb.Length > 1)
sb.RemoveLastChar();
sb.Append("}");
return sb.ToString();
}
示例2: ToUrlEncode
/// <summary>
/// Hashtable数据转URL字符串
/// </summary>
/// <param name="parameters">Hashtable</param>
/// <returns></returns>
public static string ToUrlEncode(this Hashtable parameters) {
if (parameters.IsNull() || parameters.Count == 0) return string.Empty;
StringBuilder sb = new StringBuilder();
foreach (string k in parameters.Keys) sb.AppendFormat("{0}={1}&", k.UrlEncode(), parameters[k].ToString().UrlEncode());
sb.RemoveLastChar("&");
return sb.ToString();
}
示例3: RemoveLastCharTest
public void RemoveLastCharTest()
{
var s = new StringBuilder();
s.Append("hello");
s.RemoveLastChar();
Assert.AreEqual("hell", s.ToString());
s.Clear();
Assert.AreEqual("", s.ToString());
s.RemoveLastChar();
Assert.AreEqual("", s.ToString());
s.Append('a');
s.RemoveLastChar();
Assert.AreEqual("", s.ToString());
}
示例4: GetSQL
/// <summary>
/// 分页SQL调用方法 只允许主键排序
/// </summary>
/// <param name="pageIndex">当前页码</param>
/// <param name="pageSize">每页显示数量</param>
/// <param name="tableName">表名称</param>
/// <param name="pk">主键</param>
/// <param name="fieldList">字段列表</param>
/// <param name="where">where条件 and or 开始</param>
/// <param name="groupBy">分组条件</param>
/// <param name="orderBy">排序条件</param>
/// <returns>分页SQL</returns>
public PagerSql GetSQL(int pageIndex, int pageSize, string tableName, string pk = "*", string fieldList = "*", string where = "", string groupBy = "", string orderBy = "") {
PagerSql sql = new PagerSql();
StringBuilder strSql = new StringBuilder();
strSql.Append("select ");
strSql.AppendFormat("count({0}) as total ", pk);
if (!tableName.IsNullEmpty()) strSql.AppendFormat("from {0} ", tableName);
if (!where.IsNullEmpty()) strSql.AppendFormat("where {0} ", where);
if (!groupBy.IsNullEmpty()) strSql.AppendFormat("group by {0} ", groupBy);
sql.CountSql = strSql.ToString();
//select * from Student
//where Id in (
//select top 10 Id
//from(select top 3200010 Id from Student order by Id)t
//order by Id desc)
//order by Id
//SELECT * FROM (
//SELECT TOP 页面容量 * FROM (
//SELECT TOP 页面容量*当前页码 * FROM
//表 WHERE 条件 ORDER BY 字段A ASC
//)AS TEMPTABLE1 ORDER BY 字段A DESC
//) AS TEMPTABLE2 ORDER BY 字段A ASC
StringBuilder orderByExt = new StringBuilder();
foreach (string order in orderBy.Split(',')) {
string order2 = order.Trim();
if (order2.EndsWith(" desc", true, null)) orderByExt.AppendFormat("{0} {1},", order2.Left(order2.Length - 5), "asc");
else orderByExt.AppendFormat("{0} {1},", order2.EndsWith(" asc", true, null) ? order2.Left(order2.Length - 4) : order2, "desc");
}
orderByExt.RemoveLastChar(",");
strSql.Clear();
strSql.Append("select ");
//if (distinct) strSql.Append("distinct ");
if (pageSize == 1) {
strSql.AppendFormat("top {0} ", pageSize);
strSql.AppendFormat("{0} ", fieldList);
if (!tableName.IsNullEmpty()) strSql.AppendFormat("from {0} ", tableName);
if (!where.IsNullEmpty()) strSql.AppendFormat("where {0} ", where);
if (!groupBy.IsNullEmpty()) strSql.AppendFormat("group by {0} ", groupBy);
if (!orderBy.IsNullEmpty()) strSql.AppendFormat("order by {0} ", orderBy);
} else {
if (!tableName.IsNullEmpty()) strSql.AppendFormat("{1} from (select top {0} {1} from (select top {3} {1} from {2} ", pageSize, fieldList, tableName, pageSize * pageIndex);
if (!where.IsNullEmpty()) strSql.AppendFormat("where {0} ", where);
if (!groupBy.IsNullEmpty()) strSql.AppendFormat("group by {0} ", groupBy);
if (!orderBy.IsNullEmpty()) strSql.AppendFormat("order by {0} ", orderBy);
strSql.AppendFormat(") as Top1 {0}) as Top2 {1} ", "order by " + orderByExt, "order by " + orderBy);
}
sql.DataSql = strSql.ToString();
return sql;
}
示例5: ToHtmlStringOnlyMessages
public MvcHtmlString ToHtmlStringOnlyMessages()
{
if (IsEmpty) return MvcHtmlString.Empty;
var sb = new StringBuilder();
foreach (var error in errorList)
{
sb.Append("<span>" + error.ErrorMessage.AsHtml() + "</span><br>");
}
sb.RemoveLastChar(4);
return new MvcHtmlString(sb.ToString());
}
示例6: EmitJoinSql
public override void EmitJoinSql(StringBuilder sql, List<string> withCTE, string indent)
{
if (GetJoinView().GetNativeTableRole() != null)
{
var sb = new StringBuilder();
sb.Append("[" + GetJoinView().Name + "](");
foreach (var col in GetJoinView().GetColumns())
//if (col is SchemaQuerySelectColumn)
sb.Append("[" + col.GetFullAlias() + "],");
sb.Append("[__ID__],");
sb.RemoveLastChar();
sb.Append(") AS");
sb.AppendLine("(");
sb.Append(GetJoinView().GetNativeTableRole().GetSqlText(withCTE, null));
sb.AppendLine("),");
withCTE.Add(sb.ToString());
}
else
if (GetJoinView().GetNativeQuery() != null)
{
var sb = new StringBuilder();
sb.Append("[" + GetJoinView().Name + "](");
foreach (var col in GetJoinView().GetColumns())
if (col is SchemaQuerySelectColumn)
sb.Append("[" + col.GetFullAlias() + "],");
sb.Append("[__ID__],");
sb.RemoveLastChar();
sb.Append(") AS");
sb.AppendLine("(");
sb.Append(GetJoinView().GetNativeQuery().GetSqlText(withCTE));
sb.AppendLine("),");
withCTE.Add(sb.ToString());
}
sql.AppendLine(indent + "LEFT JOIN " + GetJoinView().Get4PartsTableName() + " AS [" + GetJoinTableFillAlias() + "]");
foreach (var col in Columns)
col.EmitJoinSql(sql, withCTE, indent + " ");
var keyFieldName = "__ID__";
if (GetJoinView().GetNativeTable() != null)
keyFieldName = GetJoinView().GetNativeTable().GetPrimaryKeyColumn().Name;
sql.AppendLine(indent + "ON [" + GetJoinTableFillAlias() + "].[" + keyFieldName + "] = [" + ParentColumn.GetJoinTableFillAlias() + "].[" + Name + "]");
}
示例7: ToHtmlString
public MvcHtmlString ToHtmlString()
{
if (IsEmpty) return MvcHtmlString.Empty;
var sb = new StringBuilder();
foreach (var error in errorList)
{
if (string.IsNullOrWhiteSpace(error.ErrorObjectName))
sb.Append(@"<span>" + error.ErrorMessage.AsHtml() + "</span><br>");
else
sb.Append(@"<span>""" + error.ErrorObjectName.AsHtml() + @""": " + error.ErrorMessage.AsHtml() + "</span><br>");
}
sb.RemoveLastChar(4);
return new MvcHtmlString(sb.ToString());
}
示例8: ToJson
public override string ToJson()
{
var sb = new StringBuilder();
sb.Append("[");
foreach (var obj in props)
{
if (obj.isRaw)
sb.Append(obj.value.ToString() + ",");
else
if (obj.value is JsBaseObject)
sb.Append(((JsBaseObject)obj.value).ToJson() + ",");
else
sb.Append(Json.Encode(obj.value) + ",");
}
if (sb.Length > 1)
sb.RemoveLastChar();
sb.Append("]");
return sb.ToString();
}
示例9: LoadData
public void LoadData()
{
CheckParams();
if (CrudMode == CrudMode.View || CrudMode == CrudMode.Edit)
{
var sql = new StringBuilder();
sql.AppendLine("SELECT ");
foreach (var col in Table.Columns)
{
//if (col.Name != Table.GetPrimaryKeyColumn().Name)
sql.AppendLine(" [" + col.Name + "],");
}
sql.RemoveLastChar(3);
sql.AppendLine();
sql.AppendLine("FROM " + Table.Get4PartsTableName());
sql.AppendLine("WHERE [" + Table.GetPrimaryKeyColumn().Name + "]=" + ID.AsSQL());
using (var db = App.Schema.SqlDB.GetDbManager())
{
var dataTable = db.SetCommand(sql.ToString()).ExecuteDataTable();
if (dataTable.Rows.Count == 0)
throw new Exception("Запись не найдена в таблице " + Table.Get4PartsTableName() + ", " + Table.GetPrimaryKeyColumn().Name + "='" + ID + "'");
foreach (var col in Table.Columns)
{
if (col.Name != Table.GetPrimaryKeyColumn().Name)
Values.Add(col.Name, dataTable.Rows[0][col.Name]);
}
}
}
if (OnLoadData != null)
OnLoadData(this, null);
}
示例10: GetAttrs
public string GetAttrs()
{
var sb = new StringBuilder();
if (classes.Count > 0 || classes.Count > 0)
{
sb.Append(@"class=""");
foreach (var cls in classes)
{
if (!classes.Contains(cls))
sb.Append(cls + " ");
}
foreach (var cls in classes)
sb.Append(cls + " ");
sb.RemoveLastChar();
sb.Append(@""" ");
}
if (styles.Keys.Count > 0 || styles.Keys.Count > 0)
{
sb.Append(@"style=""");
foreach (var stl in styles)
{
if (!styles.ContainsKey(stl.Key))
sb.Append(stl.Key + ":" + stl.Value + ";");
}
foreach (var stl in styles)
sb.Append(stl.Key + ":" + stl.Value + ";");
sb.Append(@""" ");
}
foreach (var attr in attrs)
{
if (!attrs.ContainsKey(attr.Key))
sb.Append(attr.Key + "=" + attr.Value.AsJavaScript() + ";");
}
foreach (var attr in attrs)
{
sb.Append(attr.Key + "=" + attr.Value.AsJavaScript() + ";");
}
return sb.ToString();
}
示例11: EmitCreateRegisterTempTable
void EmitCreateRegisterTempTable(StringBuilder sql, string indent, SchemaTable registrTable)
{
sql.AppendLine(indent + "CREATE TABLE " + registrTable.GetRegistrTempTableName() + "(");
foreach (var col in registrTable.Columns)
{
sql.AppendLine(indent + " [" + col.Name + "] " + col.DataType.GetDeclareSql() + ",");
}
sql.RemoveLastChar(3);
sql.AppendLine();
sql.AppendLine(indent + ")");
}
示例12: EmitSaveToLogSql
public void EmitSaveToLogSql(StringBuilder sql, string id_variable, SchemaTable masterTable, string indent)
{
sql.Append(indent + "INSERT [" + GetLogTable().Name + "] (");
foreach (var col in GetLogTable().Columns)
{
if (col.Name == "__lockuser__" || col.Name == "__locksession__" || col.Name == "__locktime__") continue;
sql.Append(" [" + col.Name + "],");
}
sql.RemoveLastChar(1);
sql.AppendLine(")");
sql.Append(indent + "SELECT ");
foreach (var col in GetLogTable().Columns)
{
if (col.Name == "__lockuser__" || col.Name == "__locksession__" || col.Name == "__locktime__") continue;
if (col.Name == "__mastertimestamp__")
sql.Append(" @master_timestamp,");
//sql.Append(" ( SELECT __timestamp__ FROM [" + masterTable.Name + "] WHERE ID=[" + Name + "].[" + GetMasterColumn().Name + "]),");
else
sql.Append(" [" + col.Name + "],");
}
sql.RemoveLastChar(1);
sql.AppendLine(" FROM [" + Name + "] WHERE ID=" + id_variable);
int detNum = App.Random.Next(1, int.MaxValue / 2);
foreach (var detail in Details)
{
detNum++;
var detailTable = detail.GetDetailTable();
sql.AppendLine(indent + "DECLARE @detid" + detNum + " uniqueidentifier");
sql.AppendLine(indent + "DECLARE curs" + detNum + " CURSOR LOCAL STATIC FOR");
sql.AppendLine(indent + "SELECT ID FROM [" + detailTable.Name + "] WHERE [" + detailTable.GetMasterColumn().Name + "]=" + id_variable);
sql.AppendLine(indent + "OPEN curs" + detNum);
sql.AppendLine(indent + "FETCH NEXT FROM curs" + detNum + " INTO @detid" + detNum);
sql.AppendLine(indent + "WHILE @@FETCH_STATUS = 0");
sql.AppendLine(indent + "BEGIN");
detailTable.EmitSaveToLogSql(sql, "@detid" + detNum, this, indent + " ");
sql.AppendLine(indent + " FETCH NEXT FROM curs" + detNum + " INTO @detid" + detNum);
sql.AppendLine(indent + "END");
sql.AppendLine(indent + "CLOSE curs" + detNum);
sql.AppendLine(indent + "DEALLOCATE curs" + detNum);
}
}
示例13: EmitGenerateProvodkaDbKrPartToTempTable
void EmitGenerateProvodkaDbKrPartToTempTable(StringBuilder sql, string indent, SchemaTableProvodka prov, DbKrSaldo dbKr, SchemaTable registr, ObservableCollection<SchemaTableProvodkaField> registrFields)
{
var masterTable = this;
var detailTable = prov.OwnerTableOper.TableDetail.GetDetailTable();
var operID = prov.OwnerTableOper.ID;
sql.AppendLine(indent + "-- " + dbKr + ", регистр: " + registr.Name.AsSQL() + ", деталь: " + prov.OwnerTableOper.TableDetail.Name.AsSQL() + ", операция: '[" + prov.OwnerTableOper.Num + "] " + prov.OwnerTableOper.Name + "', проводка: " + prov.Name.AsSQL());
sql.AppendLine(indent + "INSERT " + registr.GetRegistrTempTableName() + "(");
sql.AppendLine(indent + " [" + registr.GetColumnByRole(RoleConst.Таблица_Ключ).Name + "],");
sql.AppendLine(indent + " [" + registr.GetColumnByRole(RoleConst.Регистр_ДбКр).Name + "],");
sql.AppendLine(indent + " [" + registr.GetColumnByRole(RoleConst.Регистр_КонфигДеталь).Name + "],");
sql.AppendLine(indent + " [" + registr.GetColumnByRole(RoleConst.Регистр_КонфигБизнесОперация).Name + "],");
sql.AppendLine(indent + " [" + registr.GetColumnByRole(RoleConst.Регистр_КонфигПроводка).Name + "],");
sql.AppendLine(indent + " [" + registr.GetColumnByRole(RoleConst.Регистр_Мастер).Name + "],");
sql.AppendLine(indent + " [" + registr.GetColumnByRole(RoleConst.Регистр_Деталь).Name + "],");
foreach (var field in registrFields.Where(field => registr.GetColumnByName(field.RegistrFieldName) != null))
{
sql.AppendLine(indent + " [" + field.RegistrFieldName + "],");
}
sql.RemoveLastChar(3);
sql.AppendLine();
sql.AppendLine(indent + ")");
sql.AppendLine(indent + "SELECT");
sql.AppendLine(indent + " NewID(),");
sql.AppendLine(indent + " '" + dbKr.ToString()[0] + "',");
sql.AppendLine(indent + " " + prov.OwnerTableOper.TableDetail.ID.AsSQL() + ", -- деталь: " + prov.OwnerTableOper.TableDetail.Name);
sql.AppendLine(indent + " " + prov.OwnerTableOper.ID.AsSQL() + ", -- бизнес-операция: " + prov.OwnerTableOper.Name);
sql.AppendLine(indent + " " + prov.ID.AsSQL() + ", -- проводка: " + prov.Name);
sql.AppendLine(indent + " @masterID,");
sql.AppendLine(indent + " " + detailTable.Get4PartsTableName() + ".[" + detailTable.GetColumnByRole(RoleConst.Таблица_Ключ).Name + "],");
foreach (var field in registrFields.Where(field => registr.GetColumnByName(field.RegistrFieldName) != null))
{
if (field.DataFieldName == "<пусто>")
sql.AppendLine(indent + " NULL,");
else
{
if (dbKr == DbKrSaldo.Кредит && registr.GetColumnByName(field.RegistrFieldName).ColumnRoles.Contains(RoleConst.Регистр_Мера))
sql.AppendLine(indent + " -" + detailTable.Get4PartsTableName() + ".[" + field.DataFieldName + "],");
else
sql.AppendLine(indent + " " + detailTable.Get4PartsTableName() + ".[" + field.DataFieldName + "],");
}
}
sql.RemoveLastChar(3);
sql.AppendLine();
sql.AppendLine(indent + "FROM " + detailTable.Get4PartsTableName());
sql.AppendLine(indent + "WHERE " + detailTable.Get4PartsTableName() + ".[" + detailTable.GetColumnByRole(RoleConst.ВложеннаяТаблица_БизнесОперация).Name + "]=" + operID.AsSQL() + " AND ");
sql.AppendLine(indent + " " + detailTable.Get4PartsTableName() + ".[" + detailTable.GetColumnByRole(RoleConst.ВложеннаяТаблица_Мастер).Name + "][email protected]");
}
示例14: EmitSaveRegistrFromTempTable
void EmitSaveRegistrFromTempTable(StringBuilder sql, string indent, SchemaTable registrTable)
{
sql.Append(indent + "INSERT " + registrTable.Get4PartsTableName() + "(");
foreach (var col in registrTable.Columns)
sql.Append("[" + col.Name + "],");
sql.RemoveLastChar(1);
sql.Append(") SELECT ");
foreach (var col in registrTable.Columns)
sql.Append("[" + col.Name + "],");
sql.RemoveLastChar(1);
sql.AppendLine(" FROM " + registrTable.GetRegistrTempTableName());
sql.Append(indent + "INSERT " + GetProvodkasTable().Get4PartsTableName() + "(tableRecordID,provodkaRecordID,registrID)");
sql.AppendLine(" SELECT @masterID,[" + registrTable.GetPrimaryKeyColumn().Name + "]," + registrTable.ID.AsSQL() + " FROM " + registrTable.GetRegistrTempTableName());
}
示例15: GetRequest
//#endregion
/// <summary>
/// 遍历 get/post 数据
/// </summary>
/// <returns>遍历 get/post 数据</returns>
public static string GetRequest() {
StringBuilder sb = new StringBuilder();
sb.Append("form:");
for (int i = 0; i < HttpContext.Current.Request.Form.Count; i++) sb.Append(HttpContext.Current.Request.Form.Keys[i].ToString() + "=" + HttpContext.Current.Request.Form[i].ToString() + "&");
sb.RemoveLastChar("&");
sb.Append("querystring:");
for (int i = 0; i < HttpContext.Current.Request.QueryString.Count; i++) sb.Append(HttpContext.Current.Request.QueryString.Keys[i].ToString() + "=" + HttpContext.Current.Request.QueryString[i].ToString() + "&");
sb.RemoveLastChar("&");
return sb.ToString();
}