本文整理汇总了C#中StringBuilder.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# StringBuilder.Insert方法的具体用法?C# StringBuilder.Insert怎么用?C# StringBuilder.Insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringBuilder
的用法示例。
在下文中一共展示了StringBuilder.Insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
ulong input =ulong.Parse(Console.ReadLine());
var sb =new StringBuilder();
ulong currentByte = 0;
ulong reminderIn26 = 0;
do
{
currentByte = input % 256;
reminderIn26 = currentByte % 26;
sb.Insert(0,(char)(reminderIn26 + 'A'));
if (currentByte > 25)
{
sb.Insert(0,(char)(currentByte/26 + 96));
}
input /= 256;
} while (input > 0);
Console.WriteLine(sb.ToString());
}
示例2: ConvertDecToBin
public static void ConvertDecToBin(string line)
{
int dec = int.Parse(line);
StringBuilder bin = new StringBuilder();
if (dec == 0)
{
bin.Insert(0, '0');
}
else
{
int q = dec;
while (q != 0)
{
if (q % 2 == 0)
{
bin.Insert(0, '0');
}
else
{
bin.Insert(0, '1');
}
q /= 2;
}
}
if (dec < 0)
{
Console.WriteLine("-{0}", bin);
}
else
{
Console.WriteLine("{0}", bin);
}
}
示例3: ToCostValue
public static string ToCostValue(int value)
{
StringBuilder stringBuilder = new StringBuilder ();
if (value > 0) {
int divide = 1000;
int quotient = value;
int remainder = 0;
while (quotient > 0) {
remainder = quotient % divide;
quotient /= divide;
if (quotient > 0) {
stringBuilder.Insert (0, string.Format ("{0:D3}", remainder));
stringBuilder.Insert (0, ",");
} else {
stringBuilder.Insert (0, string.Format("{0:D}", remainder));
}
}
} else {
stringBuilder.Append ("0");
}
return stringBuilder.ToString ();
}
示例4: Main
static void Main(string[] args)
{
using (StreamReader reader = File.OpenText(args[0]))
while (!reader.EndOfStream)
{
string line = reader.ReadLine();
string[] numbers = { "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM", "M", "MM", "MMM" };
int a = 1;
StringBuilder sb = new StringBuilder();
for (int i = line.Length - 1; i >= 0; i--)
{
string t = line.Substring(i, 1);
int t1 = int.Parse(t) * a;
if (t1 < 10 && t1 > 0)
sb.Insert(0, numbers[t1 - 1]);
if (t1 >= 10 && t1 < 100)
sb.Insert(0, numbers[9 + (int.Parse(t) - 1)]);
if (t1 >= 100 && t1 < 1000)
sb.Insert(0, numbers[18 + (int.Parse(t) - 1)]);
if (t1 >= 1000)
sb.Insert(0, numbers[27 + (int.Parse(t) - 1)]);
a *= 10;
}
Console.WriteLine(sb.ToString());
}
}
示例5: DecToBaseD
private static string DecToBaseD(long decNum, int baseD)
{
StringBuilder numberBaseD = new StringBuilder();
while (decNum > 0)
{
int index = 0;
char numberBaseDValue = '0';
if (((decNum % baseD) >= 0) && ((decNum % baseD <= 9)))
{
numberBaseDValue = (char)((decNum % baseD) + 48);
numberBaseD.Insert(index, numberBaseDValue);
}
else
{
numberBaseDValue = (char)((decNum % baseD) + 55);
numberBaseD.Insert(index, numberBaseDValue);
}
decNum = decNum / baseD;
index++;
}
string result = Convert.ToString(numberBaseD);
return result;
}
示例6: ConvertBase
public static string ConvertBase(string s, int b1, int b2)
{
char[] chars = s.ToUpper().ToCharArray();
bool isNeg = (chars[0] == '-');
int value = 0;
// Get int value in base b1
for (int i = (isNeg ? 1 : 0); i < chars.Length; ++i)
{
value *= b1;
value += GetIntValue(chars[i]);
}
// Convert to string in base b2
StringBuilder result = new StringBuilder();
while (value > 0)
{
char n = GetBaseSymbol(value % b2);
result.Insert(0, n);
value /= b2;
}
if (isNeg)
{
result.Insert(0, '-');
}
return result.ToString();
}
示例7: Main
public static void Main()
{
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
Console.Write("A floating-point with single precision, x = ");
float x = float.Parse(Console.ReadLine());
// float is a 32-bit floating-point number
int n = 0;
unsafe
{
int* ptr = (int*)&x;
n = *ptr;
}
StringBuilder bin = new StringBuilder();
// int is 32-bit signed integer
for (int i = 0; i < 32; i++)
{
if ((n & 1) == 0)
{
bin.Insert(0, '0');
}
else
{
bin.Insert(0, '1');
}
n >>= 1;
}
Console.WriteLine(bin);
string str = bin.ToString();
Console.WriteLine("sign = {0}, exponent = {1}, mantissa = {2}", str[0], str.Substring(1, 8), str.Substring(9));
}
示例8: Main
static void Main()
{
byte n = byte.Parse(Console.ReadLine());
StringBuilder carpet = new StringBuilder();
carpet.Capacity = n + 2;
carpet.Append('.', n/2 - 1);
carpet.Append("/\\");
carpet.Append('.', n/2 - 1);
Console.WriteLine(carpet);
for (byte i = 0; i < n/2 - 1; i++)
{
if((i & 1) == 0)
{
carpet.Insert(n/2, " ");
}
else
{
carpet.Insert(n/2, "/\\");
}
carpet.Remove(n + 1, 1);
carpet.Remove(0, 1);
Console.WriteLine(carpet);
}
carpet.Replace('/','\\', 0, n/2);
carpet.Replace('\\','/', n/2, n/2);
Console.WriteLine(carpet);
for (byte i = 0; i < n / 2 - 1; i++)
{
carpet.Remove(n / 2 - 1, 2);
carpet.Append('.', 1);
carpet.Insert(0, '.');
Console.WriteLine(carpet);
}
}
示例9: GotNewLetter
public static void GotNewLetter(string letter)
{
int index = LetterSpawner.currentWordLettersLeft.IndexOf(letter);
currentWordLetters[index] = letter;
var aStringBuilder = new StringBuilder(currentWordLettersInString);
if (index == 0)
{
aStringBuilder.Remove(1, 1);
aStringBuilder.Insert(1, letter);
}
else
{
aStringBuilder.Remove(index * 2 + 1, 1);
aStringBuilder.Insert(index * 2 + 1, letter);
}
currentWordLettersInString = aStringBuilder.ToString();
LetterSpawner.currentWordLettersLeft[index] = "*";
//for (int i = 0; i < LetterSpawner.currentWordLettersLeft.Count; i++)
// Debug.Log(LetterSpawner.currentWordLettersLeft[i]);
}
示例10: GetSelectedNodeFullPath
private String GetSelectedNodeFullPath(TreeNode node)
{
StringBuilder path = new StringBuilder();
path.Append(node.Text);
TreeNode parent = node.Parent;
if (parent == null)
{
path.Insert(0, SecurityManager.ObjectPathDelimiter);
}
else
{
while (parent != null)
{
if (parent.Text == SecurityObjectGameServerGroups)
{
break;
}
else
{
path.Insert(0, SecurityManager.ObjectPathDelimiter);
path.Insert(0, parent.Text);
parent = parent.Parent;
}
}
}
return path.ToString();
}
示例11: ConvertDecToBin
static string ConvertDecToBin(int number)
{
int baseOutput = 2;
if (number < 0)
{
number *= -1;
}
StringBuilder outputNumber = new StringBuilder();
while (number > 0)
{
long reminder = number % baseOutput;
if (reminder <= 9)
{
outputNumber.Insert(0, reminder);
}
else
{
outputNumber.Insert(0, ((char)(reminder + 55)));
}
number /= baseOutput;
}
return outputNumber.ToString();
}
示例12: Multiply
static string Multiply(string numberOne, int numberTwo)
{
List<int> digits = GetDigits(numberOne);
StringBuilder sb = new StringBuilder();
int number = 0;
for (int index = 0; index < digits.Count; index++)
{
int digitResult = digits[index] * numberTwo;
digitResult += number;
if (digitResult < 10)
{
sb.Insert(0, digitResult);
number = 0;
}
else if (digitResult >= 10)
{
sb.Insert(0, digitResult % 10);
number = digitResult / 10;
}
}
if (number > 0)
{
sb.Insert(0, number);
}
string endResult = Convert.ToString(sb);
return endResult;
}
示例13: Main
static void Main()
{
string sentence = Console.ReadLine();
string[] words = sentence.Split(' ');
StringBuilder sb = new StringBuilder();
string finalWord="";
char finalSymbol=' ';
for (int i = words.Length-1; i>=0; i--)
{
//sbList.Add(new StringBuilder(words[i]));
if (words[i].Contains('.') || words[i].Contains('!') || words[i].Contains('?'))
{
finalWord = words[i];
finalSymbol = finalWord[finalWord.Length - 1];
string final = Regex.Replace(words[i].ToString(), @"[^\w+]", "", RegexOptions.None);
sb.Insert(0, final);
sb.Insert(final.Length, ' ');
}
else
{
sb.Append(words[i]);
sb.Append(' ');
}
if (i == 0)
{
sb.Remove(sb.Length - 1, 1);
sb.Append(finalSymbol);
}
}
Console.WriteLine(sb.ToString());
}
示例14: ConvertDecToHex
public static void ConvertDecToHex(string line)
{
int dec = int.Parse(line);
StringBuilder hex = new StringBuilder();
if (dec == 0)
{
hex.Insert(0, '0');
}
else
{
int q = dec;
while (q != 0)
{
int residual = Math.Abs(q % 16);
if (residual < 10)
{
hex.Insert(0, (char)(48 + residual));
}
else
{
hex.Insert(0, (char)(65 + residual - 10));
}
q /= 16;
}
}
if (dec < 0)
{
Console.WriteLine("-{0}", hex);
}
else
{
Console.WriteLine("{0}", hex);
}
}
示例15: AddNumbersAsArray
static string AddNumbersAsArray(string firstNumber, string secondNumber)
{
if (firstNumber.Length > secondNumber.Length)
{
secondNumber = secondNumber.PadLeft(firstNumber.Length, '0');
}
if (secondNumber.Length > firstNumber.Length)
{
firstNumber = firstNumber.PadLeft(secondNumber.Length, '0');
}
int[] firstArray = CreateArrayFromString(firstNumber);
int[] secondArray = CreateArrayFromString(secondNumber);
StringBuilder result = new StringBuilder();
int reminder = 0;
for (int i = 0; i < firstArray.Length; i++)
{
result.Insert(0,(firstArray[i] + secondArray[i] + reminder) % 10);
reminder = (firstArray[i] + secondArray[i] + reminder) / 10;
}
if (reminder>0)
{
result.Insert(0,reminder);
}
return result.ToString();
}