本文整理汇总了C#中StringBuffer.Append方法的典型用法代码示例。如果您正苦于以下问题:C# StringBuffer.Append方法的具体用法?C# StringBuffer.Append怎么用?C# StringBuffer.Append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringBuffer
的用法示例。
在下文中一共展示了StringBuffer.Append方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: buf2String
/**
* convert byte array to Hex String.
*
* @param info - the propmt String
* @param buf - the byte array which will be converted
* @param offset - the start position of buf
* @param length - the converted length
* @param isOneLine16 - if true 16 bytes one line, false all bytes in one line
* @return Hex String
*/
public static string buf2String(string info, byte[] buf, int offset,
int length, bool oneLine16)
{
int i, index;
StringBuffer sBuf = new StringBuffer();
sBuf.Append(info);
for (i = 0 + offset; i < length + offset; i++)
{
if (i % 16 == 0)
{
if (oneLine16)
{
sBuf.Append(lineSeperate);
}
} else if (i % 8 == 0)
{
if (oneLine16)
{
sBuf.Append(" ");
}
}
index = buf[i] < 0 ? buf[i] + DEFAULT_TABLE_LENGTH : buf[i];
sBuf.Append(convertTable[index]);
}
return sBuf.ToString();
}
示例2: IsExtendedTest
public void IsExtendedTest(string path, bool expected)
{
StringBuffer sb = new StringBuffer();
sb.Append(path);
Assert.Equal(expected, PathInternal.IsExtended(sb));
Assert.Equal(expected, PathInternal.IsExtended(path));
}
示例3: ByteArrayToHexString
private static string ByteArrayToHexString(byte[] b)
{
StringBuffer resultSb = new StringBuffer();
for (int i = 0; i < b.Length; i++)
resultSb.Append(ByteToHexString(b[i]));
return resultSb.ToString();
}
示例4: Test1
public void Test1()
{
StringBuffer buf = new StringBuffer(100);
Assert.AreEqual(0, buf.Length);
Assert.AreEqual("", buf.ToString());
buf.Append('a');
buf.Append('b');
buf.Append('c');
Assert.AreEqual(3, buf.Length);
Assert.AreEqual("abc", buf.ToString());
buf.Clear();
Assert.AreEqual(0, buf.Length);
Assert.AreEqual("", buf.ToString());
}
示例5: FormatDouble
public static void FormatDouble(StringBuffer formatter, double value, StringView specifier, CachedCulture culture)
{
int digits;
int precision = DoublePrecision;
var fmt = ParseFormatSpecifier(specifier, out digits);
// ANDing with 0xFFDF has the effect of uppercasing the character
switch (fmt & 0xFFDF) {
case 'G':
if (digits > 15)
precision = 17;
break;
case 'E':
if (digits > 14)
precision = 17;
break;
}
var number = new Number();
var buffer = stackalloc char[MaxFloatingDigits + 1];
number.Digits = buffer;
DoubleToNumber(value, precision, ref number);
if (number.Scale == ScaleNaN) {
formatter.Append(culture.NaN);
return;
}
if (number.Scale == ScaleInf) {
if (number.Sign > 0)
formatter.Append(culture.NegativeInfinity);
else
formatter.Append(culture.PositiveInfinity);
return;
}
if (fmt != 0)
NumberToString(formatter, ref number, fmt, digits, culture);
else
NumberToCustomFormatString(formatter, ref number, specifier, culture);
}
示例6: GetColourString
string GetColourString()
{
int count = 0;
for( int i = ' '; i <= '~'; i++ ) {
if( i >= 'A' && i <= 'F' ) continue;
if( game.Drawer2D.Colours[i].A > 0 ) count++;
}
StringBuffer buffer = new StringBuffer( count * 4 );
int index = 0;
for( int i = ' '; i <= '~'; i++ ) {
if( i >= 'A' && i <= 'F' ) continue;
if( game.Drawer2D.Colours[i].A == 0 ) continue;
buffer.Append( ref index, '&' ).Append( ref index, (char)i )
.Append( ref index, '%' ).Append( ref index, (char)i );
}
return buffer.ToString();
}
示例7: ToStringBuffer
/// <summary>
/// Returns a human readable text of this entry
/// </summary>
/// <returns></returns>
public unsafe StringBuffer ToStringBuffer()
{
var buf = new StringBuffer();
buf.Append("0x");
buf.Append((uint)MethodDefinition->Method, "X");
buf.Append("+0x");
buf.Append(Offset, "X");
buf.Append(" ");
var idx = MethodName.IndexOf(' ') + 1; //Skip return type
buf.Append(MethodName, idx);
return buf;
}
示例8: ReadAllText
/// <summary>
/// Read a file with given path and return a string with it's entire contents.
/// </summary>
public static string ReadAllText(string path)
{
if (path == null)
throw new ArgumentNullException("path");
var file = new JFile(path);
if (!file.Exists() || !file.IsFile())
throw new FileNotFoundException(path);
if (!file.CanRead())
throw new UnauthorizedAccessException(path);
var reader = new FileReader(file);
try
{
var array = new char[4096];
var buffer = new StringBuffer();
int len;
while ((len = reader.Read(array, 0, array.Length)) > 0)
{
buffer.Append(array, 0, len);
}
return buffer.ToString();
}
finally
{
reader.Close();
}
}
示例9: seperateStr
/**
* Seperate String with str token
*
* @param str - the string which will be cut
* @return cut string array
*/
// @SuppressWarnings("unused")
private static string[] seperateStr(string str)
{
bool doubleSpace = false;
int wordCount = 0;
StringBuffer sb = new StringBuffer();
if (str == null || str.Length == 0)
{
return null;
}
for (int j = 0; j < str.Length; j++)
{
if (str[j] == ' ')
{
if (!doubleSpace)
wordCount++;
doubleSpace = true;
continue;
}
doubleSpace = false;
}
string[] st = new string[wordCount + 1];
int i = 0;
doubleSpace = false;
string ch = "";
for (int j = 0; j < str.Length; j++)
{
if (str[j] == ' ')
{
if (!doubleSpace)
{
st[i] = sb.ToString();
sb.Delete(0, sb.Length());
i++;
}
doubleSpace = true;
continue;
} else
{
sb.Append(str[j]);
}
doubleSpace = false;
}
st[i] = sb.ToString();
;
return st;
}
示例10: AppendHex
private static void AppendHex(StringBuffer stringbuffer, byte byte0)
{
stringbuffer.Append (toHexChar (byte0 >> 4));
stringbuffer.Append (toHexChar (byte0));
}
示例11: ReadToEnd
/// <summary>
/// Read the remainder of the reader and return it as string.
/// </summary>
public virtual string ReadToEnd()
{
var tmp = new char[4096];
var buffer = new StringBuffer();
int len;
while ((len = Read(tmp, 0, tmp.Length)) > 0)
{
buffer.Append(tmp, 0, len);
}
return buffer.ToString();
}
示例12: dump
public static string dump(byte[] abyte0, int beginIndex, int endIndex, bool spaceFlag, bool asciiFlag, bool lineNumberFlag, int linenumber)
{
byte[] cont = abyte0;
if(abyte0 == null || cont.Length == 0)
return "";
string outMsg = "";
int totalLine = (endIndex - beginIndex) / 16;
int lineNumber, q;
int offset = beginIndex;
byte byte0;
StringBuffer stringbuffer = new StringBuffer(6 + (spaceFlag?48:32));
StringBuffer asciibuffer = new StringBuffer();
string printString;
int stringcount;
int asccicount;
if (linenumber < 0)
linenumber = 0;
else
linenumber = linenumber % 10000;
for(int i = 0; i <= totalLine; i++, linenumber++)
{
if (offset < endIndex) {
stringcount = stringbuffer.Length();
asccicount = asciibuffer.Length();
stringbuffer.Delete(0, stringcount);
asciibuffer.Delete(0, asccicount);
if (lineNumberFlag) {
stringbuffer.Append("0000: ");
lineNumber = linenumber;
for(byte0 = 3; byte0 >=0; byte0--){
q = (lineNumber * 52429) >> (16+3);
stringbuffer.SetCharAt(byte0, toHexChar(lineNumber - ((q << 3) + (q << 1)))); // toHexChar(lineNumber-(q*10))
lineNumber = q;
if (0 == lineNumber) break;
}
}
for(int j = 0; j < 16; j++, offset++)
{
if (offset < endIndex) {
byte0 = abyte0[offset];
stringbuffer.Append(toHexChar(byte0 >> 4));
stringbuffer.Append(toHexChar(byte0));
if (spaceFlag)
stringbuffer.Append(' ');
if (asciiFlag) {
if (byte0 >= 0x20 && byte0 <= 0x7E)
asciibuffer.Append((char)byte0);
else
asciibuffer.Append('.');
}
} else {
stringbuffer.Append(' ');
stringbuffer.Append(' ');
if (spaceFlag)
stringbuffer.Append(' ');
}
}
if (asciiFlag)
printString = stringbuffer.ToString() + "; " + asciibuffer.ToString();
else
printString = stringbuffer.ToString();
// printLine(printString);
outMsg = outMsg + printString + "\n";
} else {
break;
}
}
printString = null;
stringbuffer = asciibuffer = null;
return outMsg;
}
示例13: Int64ToHexStr
static void Int64ToHexStr(StringBuffer formatter, ulong value, int hexBase, int digits)
{
var buffer = stackalloc char[100];
char* ptr;
if (High32(value) != 0) {
Int32ToHexChars(buffer + 100, Low32(value), hexBase, 8);
ptr = Int32ToHexChars(buffer + 100 - 8, High32(value), hexBase, digits - 8);
}
else {
if (digits < 1)
digits = 1;
ptr = Int32ToHexChars(buffer + 100, Low32(value), hexBase, digits);
}
formatter.Append(ptr, (int)(buffer + 100 - ptr));
}
示例14: loadConvert
/*
* Converts encoded \uxxxx to unicode chars and changes special saved
* chars to their original forms
*
* @param s
* the byte arrary needing convert.
* @param offset
* the offset of byte arrary
* @param lengthFlag
* Whether add one byte of length in the result.
* <code>true</code> add one byte of length in the result
* @return the convert result of the byte arrary.
*/
public static string loadConvert(byte[] s, int offset, bool lengthFlag)
{
if (null == s || (offset + (lengthFlag ? 1 : 0)) > s.Length)
throw new IllegalArgumentException ("invalid byte arrary");
char aChar;
int len = (s.Length - offset);
if (lengthFlag) {
len = s [offset] & 0xFF;
offset++;
}
StringBuffer outBuffer = new StringBuffer (len);
for (int x = offset; x < (offset + len);) {
aChar = (char)s [x++];
if (aChar == '\\') {
aChar = (char)s [x++];
if (aChar == 'u') {
// Read the xxxx
int value = 0;
for (int i = 0; i < 4; i++) {
aChar = (char)s [x++];
switch (aChar) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
value = (value << 4) + aChar - '0';
break;
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
value = (value << 4) + 10 + aChar - 'a';
break;
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
value = (value << 4) + 10 + aChar - 'A';
break;
default:
throw new IllegalArgumentException ("Malformed \\uxxxx encoding.");
}
}
outBuffer.Append ((char)value);
} else {
if (aChar == 't')
aChar = '\t';
else if (aChar == 'r')
aChar = '\r';
else if (aChar == 'n')
aChar = '\n';
else if (aChar == 'f')
aChar = '\f';
outBuffer.Append (aChar);
}
} else
outBuffer.Append (aChar);
}
return outBuffer.ToString ();
}
示例15: fillstring
/**
* Method fill string
*
* @param The string to be format.
*
*/
public static string fillstring(string formatString, int length, char fillChar, bool leftFillFlag)
{
if (null == formatString) {
formatString = "";
}
int strLen = formatString.Length;
if (strLen >= length) {
if (true == leftFillFlag) // left fill
return formatString.Substring (strLen - length, strLen);
else
return formatString.Substring (0, length);
} else {
StringBuffer sbuf = new StringBuffer ();
int fillLen = length - formatString.Length;
for (int i = 0; i < fillLen; i++) {
sbuf.Append (fillChar);
}
if (true == leftFillFlag) { // left fill
sbuf.Append (formatString);
} else {
sbuf.Insert (0, formatString);
}
string returnstring = sbuf.ToString ();
sbuf = null;
return returnstring;
}
}