本文整理汇总了C#中System.Text.StringBuilder.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# StringBuilder.Remove方法的具体用法?C# StringBuilder.Remove怎么用?C# StringBuilder.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.StringBuilder
的用法示例。
在下文中一共展示了StringBuilder.Remove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
string inputStr = Console.ReadLine();
string multipleString = "";
while (inputStr != "END")
{
multipleString += inputStr;
inputStr = Console.ReadLine();
}
string pattern = @"(?<=<a).*?\s*href\s*=\s*((""[^""]*""(?=>))|('[^']*'(?=>))|([\w\/\:\.]+\.\w{3})|(\/[^'""]*?(?=>)))";
//string pattern = @"(?s)(?:<a)(?:[\s\n_0-9a-zA-Z=""()]*?.*?)(?:href([\s\n]*)?=(?:['""\s\n]*)?)([a-zA-Z:#\/._\-0-9!?=^+]*(\([""'a-zA-Z\s.()0-9]*\))?)(?:[\s\na-zA-Z=""()0-9]*.*?)?(?:\>)";
MatchCollection collection = Regex.Matches(multipleString, pattern);
List<string> resultStrings = new List<string>();
foreach (Match match in collection)
{
StringBuilder tempStr = new StringBuilder(match.Groups[2].Value);
if (tempStr[0] == '"' || tempStr[0] == '\'')
{
tempStr.Remove(0,1);
}
if (tempStr[tempStr.Length-1] == '"' || tempStr[tempStr.Length-1] == '\'')
{
tempStr.Remove(tempStr.Length-1,1);
}
resultStrings.Add(tempStr.ToString());
Console.WriteLine(tempStr);
}
//Console.WriteLine(string.Join("\r\n",resultStrings));
}
示例2: ConvertToCanonical
/// <summary>
/// Converts input phone string to its canonical variant.
/// </summary>
/// <param name="phoneNumberString">Phone number string.</param>
/// <returns>Converted phone string.</returns>
private static string ConvertToCanonical(string phoneNumberString)
{
var resultNumber = new StringBuilder();
resultNumber.Clear();
foreach (char character in phoneNumberString)
{
if (char.IsDigit(character) || (character == '+'))
{
resultNumber.Append(character);
}
}
if (resultNumber.Length >= 2 && resultNumber[0] == '0' && resultNumber[1] == '0')
{
resultNumber.Remove(0, 1);
resultNumber[0] = '+';
}
while (resultNumber.Length > 0 && resultNumber[0] == '0')
{
resultNumber.Remove(0, 1);
}
if (resultNumber.Length > 0 && resultNumber[0] != '+')
{
resultNumber.Insert(0, DefaultCountryCode);
}
return resultNumber.ToString();
}
示例3: ConvertToCanonical
private static string ConvertToCanonical(string number)
{
StringBuilder sb = new StringBuilder();
foreach (char ch in number)
{
if (char.IsDigit(ch) || (ch == '+'))
{
sb.Append(ch);
}
}
if (sb.Length >= 2 && sb[0] == '0' && sb[1] == '0')
{
sb.Remove(0, 1);
sb[0] = '+';
}
while (sb.Length > 0 && sb[0] == '0')
{
sb.Remove(0, 1);
}
if (sb.Length > 0 && sb[0] != '+')
{
sb.Insert(0, code);
}
return sb.ToString();
}
示例4: ToBytes
public byte[] ToBytes()
{
int totalLen = 0;
byte[] bytes = new byte[TOTAL_WIDTH];
StringBuilder sb = new StringBuilder();
sb = sb.Append(CommonDataHelper.FillSpecifyWidthString(RecordID, 8));
CommonDataHelper.ResetByteBuffer(sb, ref bytes, ref totalLen, true);
sb.Remove(0, sb.Length);
sb = sb.Append(CommonDataHelper.FillSpecifyWidthFigure(RecordLength, 8));
CommonDataHelper.ResetByteBuffer(sb, ref bytes, ref totalLen, true);
sb.Remove(0, sb.Length);
sb = sb.Append(CommonDataHelper.FillSpecifyWidthFigure(RecordNumber, 8));
CommonDataHelper.ResetByteBuffer(sb, ref bytes, ref totalLen, true);
sb.Remove(0, sb.Length);
if (RecordCollection != null)
{
foreach (var record in RecordCollection)
{
Array.Copy(record.ToBytes(), 0, bytes, totalLen, record.TOTAL_WIDTH);
totalLen += record.TOTAL_WIDTH;
}
}
return bytes;
}
示例5: CreateInsertSqlString
private static string CreateInsertSqlString(Table table, IDictionary<string, object> parameters)
{
var sb = new StringBuilder();
sb.AppendLine("IF NOT EXISTS (SELECT * FROM {0} WHERE {1})".Put(table.Name, table.Columns.Where(c => c.IsPrimaryKey).Select(c => "{0} = @{0}".Put(c.Name)).Join(" AND ")));
sb.AppendLine("BEGIN");
sb.Append("INSERT INTO ");
sb.Append(table.Name);
sb.Append(" (");
foreach (var par in parameters)
{
sb.Append("[");
sb.Append(par.Key);
sb.Append("],");
}
sb.Remove(sb.Length - 1, 1);
sb.Append(") VALUES (");
foreach (var par in parameters)
{
sb.Append("@");
sb.Append(par.Key);
sb.Append(",");
}
sb.Remove(sb.Length - 1, 1);
sb.AppendLine(")");
sb.Append("END");
return sb.ToString();
}
示例6: DataTable2Json
/// <summary>
/// dataTable转换成Json格式
/// </summary>
/// <param name="dt"></param>
/// <returns></returns>
public static string DataTable2Json(DataTable dt)
{
StringBuilder jsonBuilder = new StringBuilder();
jsonBuilder.Append("{\"");
jsonBuilder.Append(dt.TableName);
jsonBuilder.Append("\":[");
//jsonBuilder.Append("[");
for (int i = 0; i < dt.Rows.Count; i++)
{
jsonBuilder.Append("{");
for (int j = 0; j < dt.Columns.Count; j++)
{
jsonBuilder.Append("\"");
jsonBuilder.Append(dt.Columns[j].ColumnName);
jsonBuilder.Append("\":\"");
jsonBuilder.Append(dt.Rows[i][j].ToString());
jsonBuilder.Append("\",");
}
jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
jsonBuilder.Append("},");
}
jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
jsonBuilder.Append("]");
jsonBuilder.Append("}");
return jsonBuilder.ToString();
}
示例7: PreProcessUntokenizedTerms
/// <summary>
/// Detects untokenized fields and sets as NotAnalyzed in analyzer
/// </summary>
private static string PreProcessUntokenizedTerms(PerFieldAnalyzerWrapper analyzer, string query, Analyzer keywordAnlyzer)
{
var untokenizedMatches = untokenizedQuery.Matches(query);
if (untokenizedMatches.Count < 1)
{
return query;
}
var sb = new StringBuilder(query);
// KeywordAnalyzer will not tokenize the values
// process in reverse order to leverage match string indexes
for (int i=untokenizedMatches.Count; i>0; i--)
{
Match match = untokenizedMatches[i-1];
// specify that term for this field should not be tokenized
analyzer.AddAnalyzer(match.Groups[1].Value, keywordAnlyzer);
Group term = match.Groups[2];
// remove enclosing "[[" "]]" from term value (again in reverse order)
sb.Remove(term.Index+term.Length-2, 2);
sb.Remove(term.Index, 2);
}
return sb.ToString();
}
示例8: armaFiltro
/// <summary>
/// Arma los filtros que se aplicarán para regenerar
/// el reporte. Depende de cada implementación del
/// IPanelFiltros.
/// </summary>
private string armaFiltro()
{
var sb = new StringBuilder();
// Filtros de fecha
// Si no selecciona ningún filtro, genera una excepción.
if (chkListaEntidades.CheckedItems.Count != 0 &&
chkEstadosGestion.CheckedItems.Count != 0)
{
// Filtros de entidades
sb.Append("(");
foreach (object item in chkListaEntidades.CheckedItems)
sb.Append(string.Format("Entidad = '{0}' or ", item));
sb.Remove(sb.Length - 4, 4);
sb.Append(")");
// Filtros de estados de cuenta
sb.Append(" and (");
foreach (object item in chkEstadosGestion.CheckedItems)
sb.Append(string.Format("Estado = '{0}' or ", item));
sb.Remove(sb.Length - 4, 4);
sb.Append(")");
return sb.ToString();
}
throw new Exception(Mensaje.TextoMensaje("REPORTE-NOFILTRO"));
}
示例9: insertSupplier
/*
* 插入新供应商
*/
public void insertSupplier(Dictionary<String,String> supplierInformationDict)
{
StringBuilder sqlText = new StringBuilder("insert into supplier(");
foreach (var item in supplierInformationDict)
{
sqlText.Append(item.Key);
sqlText.Append(",");
}
sqlText.Remove(sqlText.Length-1,1); //移除,(多余的逗号)
sqlText.Append(") values(");
SqlParameter[] sqlParameter = new SqlParameter[supplierInformationDict.Count];
int index = 0;
foreach (var item in supplierInformationDict)
{
sqlText.Append("@");
sqlText.Append(item.Key);
sqlText.Append(",");
if (index != supplierInformationDict.Count - 1)
{
sqlParameter[index] = new SqlParameter("@" + item.Key, SqlDbType.VarChar);
}
else
{
sqlParameter[index] = new SqlParameter("@" + item.Key, SqlDbType.DateTime);
}
sqlParameter[index].Value = item.Value;
index++;
}
sqlText.Remove(sqlText.Length - 1, 1); //移除,(多余的逗号)
sqlText.Append(")");
DBHelper.ExecuteNonQuery(sqlText.ToString(),sqlParameter);
}
示例10: MoveToBack
private static StringBuilder MoveToBack(StringBuilder test, Tuple<int, int> location){
var charToMoveToBack = test[location.Item1];
test = test.Remove(location.Item1, 1);
test = test.Remove(location.Item2 - 1, 1);
test = test.Append(charToMoveToBack.ToString());
return test;
}
示例11: CreateListRegularExpression
/// <summary>Creates a regular expression that represents a comma-delimited list of the given regular expression pattern.</summary>
/// <param name="expression">The regular expression.</param>
/// <returns>A new regular expression.</returns>
private static string CreateListRegularExpression(string expression)
{
var emailRegularExpressionBuilder = new StringBuilder(expression);
var prefixBuilder = new StringBuilder();
if (emailRegularExpressionBuilder[0] == '^')
{
prefixBuilder.Append('^');
emailRegularExpressionBuilder.Remove(0, 1);
}
if (emailRegularExpressionBuilder.ToString(0, 2).Equals(@"\b", StringComparison.Ordinal))
{
prefixBuilder.Append(@"\b");
emailRegularExpressionBuilder.Remove(0, 2);
}
var suffixBuilder = new StringBuilder();
if (emailRegularExpressionBuilder[emailRegularExpressionBuilder.Length - 1] == '$')
{
suffixBuilder.Append('$');
emailRegularExpressionBuilder.Remove(emailRegularExpressionBuilder.Length - 1, 1);
}
if (emailRegularExpressionBuilder.ToString(emailRegularExpressionBuilder.Length - 2, 2)
.Equals(@"\b", StringComparison.Ordinal))
{
suffixBuilder.Append(@"\b");
emailRegularExpressionBuilder.Remove(emailRegularExpressionBuilder.Length - 2, 2);
}
return string.Format(CultureInfo.InvariantCulture, @"{0}{1}(?:,\s*{1})*{2}", prefixBuilder, emailRegularExpressionBuilder, suffixBuilder);
}
示例12: BuildName
private static string BuildName(List<ObjectCommandPropertyValue> propValues)
{
StringBuilder builder = new StringBuilder();
foreach (ObjectCommandPropertyValue value2 in propValues)
{
if ((value2 != null) && (value2.PropertyValue != null))
{
ICollection propertyValue = value2.PropertyValue as ICollection;
if (propertyValue != null)
{
builder.Append("{");
int length = builder.Length;
foreach (object obj2 in propertyValue)
{
builder.Append(string.Format(CultureInfo.InvariantCulture, "{0}, ", new object[] { obj2.ToString() }));
}
builder = (builder.Length > length) ? builder.Remove(builder.Length - 2, 2) : builder;
builder.Append("}, ");
}
else
{
builder.Append(string.Format(CultureInfo.InvariantCulture, "{0}, ", new object[] { value2.PropertyValue.ToString() }));
}
}
}
if (builder.Length < 2)
{
return string.Empty;
}
return builder.Remove(builder.Length - 2, 2).ToString();
}
示例13: ExportToCsv
public static void ExportToCsv(System.Web.HttpResponse response, DataTable exportData, string exportName)
{
response.Clear();
byte[] BOM = { 0xEF, 0xBB, 0xBF }; // UTF-8 BOM karakterleri
response.BinaryWrite(BOM);
StringBuilder sb = new StringBuilder();
foreach (DataColumn dc in exportData.Columns)
{
sb.Append((char)(34) + dc.ColumnName + (char)(34));
sb.Append(";");
}
sb = sb.Remove(sb.Length - 1, 1);
sb.AppendLine();
foreach (DataRow dr in exportData.Rows)
{
for (int i = 0; i < exportData.Columns.Count; i++)
{
sb.Append(dr[i].ToString().Replace(';', ',').Replace('\n', ' ').Replace('\t', ' ').Replace('\r', ' '));
sb.Append(";");
}
sb = sb.Remove(sb.Length - 1, 1);
sb.AppendLine();
}
response.ContentType = "text/csv";
response.AppendHeader("Content-Disposition", "attachment; filename=" + exportName + ".csv");
response.Write(sb.ToString());
response.End();
}
示例14: ReadLine
public static string ReadLine(this Stream ns)
{
var builder = new StringBuilder();
byte cur = 0;
byte prev = 0;
while (true)
{
if (cur == 10)
{
if (prev == 13)
{
// Remove /r/n
builder.Remove(builder.Length - 2, 2);
}
else
{
// Remove /n
builder.Remove(builder.Length - 1, 1);
}
break;
}
prev = cur;
cur = (byte)ns.ReadByte();
builder.Append((char)cur);
}
return builder.ToString();
}
示例15: DataTable2JsonAfterRow
/// <summary>
/// dataTable中的全部记录转换成Json格式
/// </summary>
/// <param name="dt"></param>
/// <returns></returns>
// public static string DataTable2Json(DataTable dt,)
//{
// return DataTable2JsonAfterRow(dt, 0,row);
// }
/// <summary>
///
///
/// </summary>
/// <param name="dt"></param>
/// <param name="after">起行+1</param>
/// <returns></returns>
public static string DataTable2JsonAfterRow(DataTable dt, int after ,int row,int total)
{
StringBuilder jsonBuilder = new StringBuilder();
if (dt.Rows.Count == 0)
{
jsonBuilder.Append("{\"total\":" + total.ToString());
jsonBuilder.Append(",\"rows\":[]}");
return jsonBuilder.ToString();
}
jsonBuilder.Append("{\"total\":"+total.ToString());
jsonBuilder.Append(dt.TableName);
jsonBuilder.Append(",\"rows\":[");
for (int i = after; i < dt.Rows.Count; i++)
{
jsonBuilder.Append("{");
for (int j = 0; j < dt.Columns.Count; j++)
{
jsonBuilder.Append("\"");
jsonBuilder.Append(dt.Columns[j].ColumnName);
jsonBuilder.Append("\":\"");
jsonBuilder.Append(dt.Rows[i][j].ToString());
jsonBuilder.Append("\",");
}
jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
jsonBuilder.Append("},");
}
jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
jsonBuilder.Append("]");
jsonBuilder.Append("}");
return jsonBuilder.ToString();
}