本文整理汇总了C#中StringBuilder.Append方法的典型用法代码示例。如果您正苦于以下问题:C# StringBuilder.Append方法的具体用法?C# StringBuilder.Append怎么用?C# StringBuilder.Append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringBuilder
的用法示例。
在下文中一共展示了StringBuilder.Append方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ByteArrayToString
public string ByteArrayToString(byte[] data)
{
StringBuilder sb = new StringBuilder();
byte[] newdata = new byte[3];
// 2 bytes 3 characters
// First, bits with weight 4,8,16,32,64 of byte 1
// Second, bits with weight 32,64,128 of byte 2 plus bits with weight 1,2 from byte 1
// Third, bits with weight 1,2,4,8,16 of byte 2
newdata[0] = (byte)(((int)data[0]& 0x7c)/4);
newdata[1] = (byte)((((int)data[0] & 0x03)*8) + (((int)data[1] & 0xe0) / 32));
newdata[2] = (byte)((int)data[1] & 0x1f);
for (int i = 0; i < newdata.Length; i++)
{
if (newdata[i] >= 0x01 && newdata[i] <= 0x1a)
sb.Append(((char)((((int)newdata[i])) + 65 - 0x01)));
else if (newdata[i] == 0x1b)
sb.Append('-');
else if (newdata[i] == 0x00)
sb.Append(' ');
}
return sb.ToString();
}
示例2: ToString
public override void ToString(StringBuilder sb, IQueryWithParams query)
{
if (this.op == CriteriaOperator.Like ||
this.op == CriteriaOperator.NotLike)
{
var valueCriteria = this.right as ValueCriteria;
if (query.Dialect.IsCaseSensitive() &&
!ReferenceEquals(null, valueCriteria) &&
valueCriteria.Value is string)
{
sb.Append("UPPER(");
this.left.ToString(sb, query);
sb.Append(this.op == CriteriaOperator.Like ? ") LIKE UPPER(" : ") NOT LIKE UPPER(");
this.right.ToString(sb, query);
sb.Append(")");
}
else
{
this.left.ToString(sb, query);
sb.Append(this.op == CriteriaOperator.Like ? " LIKE " : " NOT LIKE ");
this.right.ToString(sb, query);
}
}
else
{
this.left.ToString(sb, query);
sb.Append(opText[(int)this.op - (int)CriteriaOperator.AND]);
this.right.ToString(sb, query);
}
}
示例3: BuildExceptionReport
static StringBuilder BuildExceptionReport(Exception e, StringBuilder sb, int d)
{
if (e == null)
return sb;
sb.AppendFormat("Exception of type `{0}`: {1}", e.GetType().FullName, e.Message);
var tle = e as TypeLoadException;
if (tle != null)
{
sb.AppendLine();
Indent(sb, d);
sb.AppendFormat("TypeName=`{0}`", tle.TypeName);
}
else // TODO: more exception types
{
}
if (e.InnerException != null)
{
sb.AppendLine();
Indent(sb, d); sb.Append("Inner ");
BuildExceptionReport(e.InnerException, sb, d + 1);
}
sb.AppendLine();
Indent(sb, d); sb.Append(e.StackTrace);
return sb;
}
示例4: FormatMessage
internal static string FormatMessage (string msg)
{
StringBuilder sb = new StringBuilder ();
bool wasWs = false;
foreach (char ch in msg) {
if (ch == ' ' || ch == '\t') {
if (!wasWs)
sb.Append (' ');
wasWs = true;
continue;
}
wasWs = false;
sb.Append (ch);
}
var doc = TextDocument.CreateImmutableDocument (sb.ToString());
foreach (var line in doc.Lines) {
string text = doc.GetTextAt (line.Offset, line.Length).Trim ();
int idx = text.IndexOf (':');
if (text.StartsWith ("*", StringComparison.Ordinal) && idx >= 0 && idx < text.Length - 1) {
int offset = line.EndOffsetIncludingDelimiter;
msg = text.Substring (idx + 1) + doc.GetTextAt (offset, doc.TextLength - offset);
break;
}
}
return msg.TrimStart (' ', '\t');
}
示例5: HandlerData
protected string HandlerData(HttpContext context)
{
StringBuilder sbResult = new StringBuilder();
try
{
string strPath = CY.Utility.Common.RequestUtility.GetQueryString("path");
string strName = CY.Utility.Common.RequestUtility.GetQueryString("name");
if (string.IsNullOrEmpty(strPath) || string.IsNullOrEmpty(strName))
{
return sbResult.Append("{success:false,msg:'传递的参数错误ofx001!'}").ToString();
}
string appPath = CY.Utility.Common.RequestUtility.CurPhysicalApplicationPath;
string dirPath = appPath + "Content\\Instrument\\Img\\";
string fileName = strPath.Substring(strPath.LastIndexOf("/"), strPath.Length);
if (File.Exists(dirPath + fileName))
{
File.Delete(dirPath + fileName);
sbResult.Append("{success:true}");
}
else
{
return sbResult.Append("{success:false,msg:'该文件件不存在!'}").ToString();
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
}
return sbResult.ToString();
}
示例6: TestEmail
string TestEmail(Settings settings)
{
string email = settings.Email;
string smtpServer = settings.SmtpServer;
string smtpServerPort = settings.SmtpServerPort.ToString();
string smtpUserName = settings.SmtpUserName;
string smtpPassword = settings.SmtpPassword;
string enableSsl = settings.EnableSsl.ToString();
var mail = new MailMessage
{
From = new MailAddress(email, smtpUserName),
Subject = string.Format("Test mail from {0}", smtpUserName),
IsBodyHtml = true
};
mail.To.Add(mail.From);
var body = new StringBuilder();
body.Append("<div style=\"font: 11px verdana, arial\">");
body.Append("Success");
if (HttpContext.Current != null)
{
body.Append(
"<br /><br />_______________________________________________________________________________<br /><br />");
body.AppendFormat("<strong>IP address:</strong> {0}<br />", Utils.GetClientIP());
body.AppendFormat("<strong>User-agent:</strong> {0}", HttpContext.Current.Request.UserAgent);
}
body.Append("</div>");
mail.Body = body.ToString();
return Utils.SendMailMessage(mail, smtpServer, smtpServerPort, smtpUserName, smtpPassword, enableSsl.ToString());
}
示例7: Join
internal static string Join(object thisob, string separator, bool localize)
{
StringBuilder builder = new StringBuilder();
uint num = Microsoft.JScript.Convert.ToUint32(LateBinding.GetMemberValue(thisob, "length"));
if (num > 0x7fffffff)
{
throw new JScriptException(JSError.OutOfMemory);
}
if (num > builder.Capacity)
{
builder.Capacity = (int) num;
}
for (uint i = 0; i < num; i++)
{
object valueAtIndex = LateBinding.GetValueAtIndex(thisob, (ulong) i);
if ((valueAtIndex != null) && !(valueAtIndex is Missing))
{
if (localize)
{
builder.Append(Microsoft.JScript.Convert.ToLocaleString(valueAtIndex));
}
else
{
builder.Append(Microsoft.JScript.Convert.ToString(valueAtIndex));
}
}
if (i < (num - 1))
{
builder.Append(separator);
}
}
return builder.ToString();
}
示例8: ComposeSentence
public string ComposeSentence(string[] words)
{
StringBuilder text = new StringBuilder();
bool hasSpace = true;
for (int i = 0; i < words.Length; i++)
{
if (IsNoSpacePunctuation(words[i])) text.Append(words[i]);
else if (IsReverseSpacePunctuation(words[i]))
{
hasSpace = false;
text.Append(" " + words[i]);
}
else if (i == 0)
{
text.Append(StaticHelper.FirstLetterToUpper(words[i]));
}
else
{
if (words[i - 1] == ".") words[i] = StaticHelper.FirstLetterToUpper(words[i]);
if (hasSpace) text.Append(" " + words[i]);
else text.Append(words[i]);
hasSpace = true;
}
}
string newText = text.ToString().Trim();
return newText;
}
示例9: UpdateDrugMonthMax
/// <summary>
/// 更新购药月封顶线
/// </summary>
/// <returns></returns>
public bool UpdateDrugMonthMax(decimal monthDrugMax)
{
bool result = false;
try
{
StringBuilder strSql = new StringBuilder();
strSql.Append(" update T_Med_MonthDrugMax set");
strSql.Append(" [email protected] ");
SqlParameter[] parameters =
{
new SqlParameter("@MonthDrugMax", SqlDbType.Decimal)
};
parameters[0].Value = monthDrugMax;
if (SqlHelper.ExecuteNonQuery(SqlHelper.connString, CommandType.Text, strSql.ToString(), parameters) > 0) //更改成功 影响条数为1
{
result = true; //更新成功设置为true
}
}
catch (Exception e)
{
Log4Net.LogWrite("err", "Med_DAL:DAL_MonthDrugMax//UpdateDrugMonthMax" + e.Message); //发生异常,记录
}
return result;
}
示例10: MergeFiles
private static void MergeFiles(){
Console.WriteLine( "Please paste or type the manifest file path here..." );
String manifestPath = Console.ReadLine();
if (manifestPath == null) throw new InvalidDataException();
if (Directory.Exists( manifestPath ) == false){
Console.WriteLine( "File isn't exsited." );
return;
}
List<String> paths = Directory.GetFiles( manifestPath, "*.sql" ).ToList();
var stringBuilder = new StringBuilder();
foreach (var path in paths){
if (File.Exists( path ) == false) continue;
stringBuilder.Append( "\r\nGO\n\r\n" );
stringBuilder.Append( File.ReadAllText( path, Encoding.GetEncoding( 65001 ) ) );
}
if (File.Exists( @"r:\\output.sql" )) File.Delete( @"r:\\output.sql" );
File.WriteAllText( @"r:\\output.sql", stringBuilder.ToString() );
}
示例11: OnActionExecuted
public void OnActionExecuted(ActionExecutedContext filterContext)
{
// don't touch temp data if there's no work to perform
if (!_notifier.List().Any())
return;
var tempData = filterContext.Controller.TempData;
// initialize writer with current data
var sb = new StringBuilder();
if (tempData.ContainsKey(TempDataMessages)) {
sb.Append(tempData[TempDataMessages]);
}
// accumulate messages, one line per message
foreach (var entry in _notifier.List()) {
sb.Append(Convert.ToString(entry.Type))
.Append(':')
.AppendLine(entry.Message.ToString())
.AppendLine("-");
}
// assign values into temp data
// string data type used instead of complex array to be session-friendly
tempData[TempDataMessages] = sb.ToString();
}
示例12: ToString
public override String ToString()
{
StringBuilder buffer = new StringBuilder();
buffer.Append("[FBI]\n");
buffer.Append(" .xBasis = ")
.Append("0x").Append(HexDump.ToHex(XBasis))
.Append(" (").Append(XBasis).Append(" )");
buffer.Append(Environment.NewLine);
buffer.Append(" .yBasis = ")
.Append("0x").Append(HexDump.ToHex(YBasis))
.Append(" (").Append(YBasis).Append(" )");
buffer.Append(Environment.NewLine);
buffer.Append(" .heightBasis = ")
.Append("0x").Append(HexDump.ToHex(HeightBasis))
.Append(" (").Append(HeightBasis).Append(" )");
buffer.Append(Environment.NewLine);
buffer.Append(" .scale = ")
.Append("0x").Append(HexDump.ToHex(Scale))
.Append(" (").Append(Scale).Append(" )");
buffer.Append(Environment.NewLine);
buffer.Append(" .indexToFontTable = ")
.Append("0x").Append(HexDump.ToHex(IndexToFontTable))
.Append(" (").Append(IndexToFontTable).Append(" )");
buffer.Append(Environment.NewLine);
buffer.Append("[/FBI]\n");
return buffer.ToString();
}
示例13: ReplaceTarget
public static void ReplaceTarget(List<string> words)
{
using (StreamReader reader = new StreamReader("test.txt"))
{
using (StreamWriter writer = new StreamWriter("temp.txt"))
{
StringBuilder sb = new StringBuilder();
sb.Append(@"\b(");
foreach (string word in words) sb.Append(word + "|");
sb.Remove(sb.Length - 1, 1);
sb.Append(@")\b");
string pattern = @sb.ToString();
Regex rgx = new Regex(pattern, RegexOptions.IgnoreCase);
for (string line; (line = reader.ReadLine()) != null; )
{
string newLine = rgx.Replace(line, "");
writer.WriteLine(newLine);
}
}
}
File.Delete("test.txt");
File.Move("temp.txt", "test.txt");
}
示例14: AppendCodeStringStmt
internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) {
format.ReflowComment(res, this.GetProceedingWhiteSpace(ast));
res.Append("with");
var itemWhiteSpace = this.GetListWhiteSpace(ast);
int whiteSpaceIndex = 0;
for (int i = 0; i < _items.Length; i++) {
var item = _items[i];
if (i != 0) {
if (itemWhiteSpace != null) {
res.Append(itemWhiteSpace[whiteSpaceIndex++]);
}
res.Append(',');
}
item.ContextManager.AppendCodeString(res, ast, format);
if (item.Variable != null) {
if (itemWhiteSpace != null) {
res.Append(itemWhiteSpace[whiteSpaceIndex++]);
} else {
res.Append(' ');
}
res.Append("as");
item.Variable.AppendCodeString(res, ast, format);
}
}
_body.AppendCodeString(res, ast, format);
}
示例15: Add
/// <summary>
/// ����һ������
/// </summary>
public int Add(ECSMS.Model.EC_UserSmsAccount model)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("insert into EC_UserSmsAccount(");
strSql.Append("UserId,SmsType,InitNum,LargessNum,LeaveNum,AwokeNum)");
strSql.Append(" values (");
strSql.Append("@UserId,@SmsType,@InitNum,@LargessNum,@LeaveNum,@AwokeNum)");
strSql.Append(";select @@IDENTITY");
SqlParameter[] parameters = {
new SqlParameter("@UserId", SqlDbType.Int,4),
new SqlParameter("@SmsType", SqlDbType.VarChar,10),
new SqlParameter("@InitNum", SqlDbType.Int,4),
new SqlParameter("@LargessNum", SqlDbType.Int,4),
new SqlParameter("@LeaveNum", SqlDbType.Int,4),
new SqlParameter("@AwokeNum", SqlDbType.Int,4)};
parameters[0].Value = model.UserId;
parameters[1].Value = model.SmsType;
parameters[2].Value = model.InitNum;
parameters[3].Value = model.LargessNum;
parameters[4].Value = model.LeaveNum;
parameters[5].Value = model.AwokeNum;
object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
if (obj == null)
{
return 0;
}
else
{
return Convert.ToInt32(obj);
}
}