本文整理汇总了C#中StringBuilder.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# StringBuilder.Remove方法的具体用法?C# StringBuilder.Remove怎么用?C# StringBuilder.Remove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringBuilder
的用法示例。
在下文中一共展示了StringBuilder.Remove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PrintPoli
static string PrintPoli(decimal[] polynomial)
{
StringBuilder returnString = new StringBuilder();
for (int i = polynomial.Length - 1; i >= 0; i--)
{
if (polynomial[i] != 0)
{
returnString.Append(polynomial[i] > 0 ? " + " : " - ");
returnString.Append(Math.Abs(polynomial[i]));
if (i != 0)
{
returnString.Append(i > 1 ? "x^" + i : "x");
}
}
}
if (returnString[1] != '-')
{
returnString.Remove(0, 3);
}
else
{
returnString.Remove(0, 1);
}
return returnString.ToString();
}
示例2: PrintPolynomial
private static void PrintPolynomial(decimal[] polynomial)
{
StringBuilder returnString = new StringBuilder();
for (int i = polynomial.Length - 1; i >= 0; i--)
{
if (polynomial[i] != 0)
{
returnString.Append(polynomial[i] > 0 ? " + " : " - ");
returnString.Append(Math.Abs(polynomial[i]));
if (i != 0)
{
returnString.Append(i > 1 ? "x^" + i : "x");
}
}
}
if (returnString[1] != '-')
{
returnString.Remove(0, 3);
}
else
{
returnString.Remove(0, 1);
}
Console.Write(returnString);
}
示例3: Main
static void Main()
{
string sentence = "C# is not C++, not PHP and not Delphi!";
char[] separator = { ' ', '!' ,','};
string[] words = sentence.Split(separator,StringSplitOptions.RemoveEmptyEntries);
StringBuilder result = new StringBuilder();
int currentWords = words.Length - 1;
string[] subSentence = sentence.Split(',');
foreach (var item in subSentence)
{
string newitem = item.Trim();
int countWordsSub = newitem.Split(' ').Length;
for (int i = 0; i < countWordsSub; i++)
{
result.AppendFormat("{0} ", words[currentWords]);
currentWords--;
}
result.Remove(result.ToString().Length - 1, 1);
result.Append(", ");
}
result.Remove(result.ToString().Length - 2, 2);
result.Append("!");
Console.WriteLine(sentence);
Console.WriteLine();
Console.WriteLine(result.ToString());
}
示例4: GetJson
public static string GetJson(DataTable dt, String page, String rows)
{
int totalRecord = dt.Rows.Count; // 总记录数(应根据数据库取得,在此只是模拟)
int totalPage = totalRecord % int.Parse(rows) == 0 ? totalRecord
/ int.Parse(rows) : totalRecord / int.Parse(rows)
+ 1; // 计算总页数
int index = (int.Parse(page) - 1) * int.Parse(rows); // 开始记录数
int pageSize = int.Parse(rows);
// 以下模拟构造JSON数据对象
StringBuilder jsonBuilder = new StringBuilder();
jsonBuilder.Append("{\"page\":" + page + ",\"total\":" + totalPage + ",\"records\":" + totalRecord + ",\"rows\"");
jsonBuilder.Append(":[");
for (int i = index; i < pageSize + index && i < totalRecord; i++)
{
jsonBuilder.Append("{\"id\":" + i + ",\"cell\":[");
for (int j = 0; j < dt.Columns.Count; j++)
{
jsonBuilder.Append("\"" + dt.Rows[i][j].ToString().Trim() + "\",");
}
jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
jsonBuilder.Append("]},");
}
jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
jsonBuilder.Append("]");
jsonBuilder.Append("}");
return jsonBuilder.ToString();
}
示例5: BLOCK
public BLOCK(StringBuilder raw)
{
if (raw[0] != BLOCK_START)
throw new ArgumentException("Expected block start token");
do
{
raw.Remove(0, 1);
LTrim(raw);
//TODO: Special case, test for empty block
if (raw[0] == BLOCK_END)
break;
if (raw[0] != BLOCK_SEPARATOR)
{
var element = Element.From(raw);
_elements.Add(element);
LTrim(raw);
}
}
while (raw[0] == BLOCK_SEPARATOR);
if (raw[0] != BLOCK_END)
throw new ArgumentException("Expected end of block");
raw.Remove(0, 1);
}
示例6: Main
static void Main()
{
string text = Console.ReadLine();
int start = text.IndexOf("<upcase>");
int end = text.IndexOf("</upcase>") + 9;
while (start != -1 && end != -1)
{
StringBuilder sb = new StringBuilder(text);
for (int i = start; i < end; i++)
{
if (sb[i] >= 'a' && sb[i] <= 'z')
{
sb[i] -= (char)32;
}
}
sb = sb.Remove(end - 9, 9);
sb = sb.Remove(start, 8);
text = sb.ToString();
start = text.IndexOf("<upcase>");
end = text.IndexOf("</upcase>") + 9;
}
Console.WriteLine(text);
}
示例7: 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);
}
}
示例8: GetRelativePath
/// <summary>
/// Turns the given full path into a relative one starting just above the given directory.
/// For example, "GetRelativePath("C:/A/B/C", "B")" returns "B/C".
/// Returns "null" if the given folder can't be found.
/// </summary>
/// <remarks>
/// As a side effect, all '/' or '\' slashes will be changed
/// to the correct directory separator char for this platform.
/// </remarks>
/// <param name="startFolder">
/// The folder that will appear at the top of the returned path.
/// </param>
public static string GetRelativePath(string fullPath, string startFolder)
{
StringBuilder sb = new StringBuilder(fullPath);
if ('/' != Path.DirectorySeparatorChar)
{
sb.Replace('/', Path.DirectorySeparatorChar);
}
if ('\\' != Path.DirectorySeparatorChar)
{
sb.Replace('\\', Path.DirectorySeparatorChar);
}
//Get the start of the given folder in the path string.
int folderLoc = sb.ToString().IndexOf(Path.DirectorySeparatorChar +
startFolder +
Path.DirectorySeparatorChar);
if (folderLoc < 0 && sb.ToString().StartsWith(startFolder + Path.DirectorySeparatorChar))
{
folderLoc = 0;
}
//If the given folder was found, cut out everything before that.
if (folderLoc >= 0)
{
sb.Remove(0, folderLoc);
if (sb[0] == Path.DirectorySeparatorChar)
sb.Remove(0, 1);
return sb.ToString();
}
else
{
return null;
}
}
示例9: Main
static void Main()
{
string line = "aaaaabbbbbcdddeeeedssaa";
StringBuilder sb = new StringBuilder();
sb.Append(line);
char compare = sb[0];
int startIndex = 0;
int sum = 1;
int count = 0;
for (int i = 1; i < sb.Length; i++)
{
if (compare == sb[i])
{
sum++;
}
else
{
sb.Remove(startIndex + 1, sum - 1);
sum = 1;
count++;
startIndex = count;
compare = sb[startIndex];
i = count;
}
}
sb.Remove(startIndex + 1, sum - 1);
Console.WriteLine(sb.ToString());
}
示例10: GetRelativePath
/// <summary>
/// Turns the given full path into a relative one starting just above the given directory.
/// For example, "GetRelativePath("C:/A/B/C", "B")" returns "B/C".
/// Returns "null" if the given folder can't be found.
/// </summary>
/// <remarks>
/// As a side effect, all '/' or '\' slashes will be changed
/// to the correct directory separator char for this platform.
/// </remarks>
/// <param name="startFolder">
/// The folder that will appear at the top of the returned path.
/// </param>
public static string GetRelativePath(string fullPath, string startFolder)
{
StringBuilder sb = new StringBuilder(fullPath);
if ('/' != Path.DirectorySeparatorChar)
{
sb.Replace('/', Path.DirectorySeparatorChar);
}
if ('\\' != Path.DirectorySeparatorChar)
{
sb.Replace('\\', Path.DirectorySeparatorChar);
}
int folderLoc = sb.ToString().IndexOf(Path.DirectorySeparatorChar +
startFolder +
Path.DirectorySeparatorChar);
if (folderLoc >= 0)
{
sb.Remove(0, folderLoc);
if (sb[0] == Path.DirectorySeparatorChar)
sb.Remove(0, 1);
return sb.ToString();
}
else
{
return null;
}
}
示例11: Main
static void Main()
{
int n = int.Parse(Console.ReadLine());
int f = int.Parse(Console.ReadLine());
int r = int.Parse(Console.ReadLine());
string nInBinary = Convert.ToString(n, 2).PadLeft(19, '0');
StringBuilder bin = new StringBuilder(nInBinary);
char charAtFPos = bin[bin.Length - 1 - f];
bin.Remove(bin.Length - 1 - f, 1);
for (int i = 0; i < r; i++)
{
char right = bin[bin.Length - 1];
bin.Remove(bin.Length - 1, 1);
bin.Insert(0, right);
}
bin.Insert(bin.Length - f, charAtFPos);
int res = Convert.ToInt32(bin.ToString(), 2);
Console.WriteLine(res);
}
示例12: 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]);
}
示例13: SetTextOnMesh
public static void SetTextOnMesh(string text, TextMesh mesh, float boundary)
{
//TODO: This is rather naive. Hyphenation?
text = text.Replace(System.Environment.NewLine, "");
string[] words = text.Split(' ');
var sb = new StringBuilder();
var renderer = mesh.GetComponent<Renderer>();
for (int i = 0; i < words.Length; i++)
{
sb.Append(words[i] + " ");
mesh.text = sb.ToString();
if (renderer.bounds.size.x >= boundary && i!=0)
{
//TODO: This crashes on first word. why +2 anyway?
sb.Remove(sb.Length - (words[i].Length + 1), words[i].Length + 1);
sb.Append(System.Environment.NewLine);
sb.Append(words[i] + " ");
}
}
sb.Remove(sb.Length - 1, 1);
mesh.text = sb.ToString();
}
示例14: Main
static void Main()
{
int number = int.Parse(Console.ReadLine());
List<int> bitsPositions = new List<int>();
List<string> commands = new List<string>();
while (true)
{
string bitPos = Console.ReadLine();
if (bitPos == "quit")
{
break;
}
bitsPositions.Add(int.Parse(bitPos));
string command = Console.ReadLine();
commands.Add(command);
}
StringBuilder manipulate = new StringBuilder();
string numberAsBits = Convert.ToString(number, 2).PadLeft(32, '0');
manipulate.Append(numberAsBits);
for (int i = 0; i < commands.Count; i++)
{
string currentCommand = commands[i];
int pos = 31 - bitsPositions[i];
switch (currentCommand)
{
case "flip":
if (manipulate[pos] == '0')
{
manipulate.Replace('0', '1', pos, 1);
}
else
{
manipulate.Replace('1', '0', pos, 1);
}
break;
case "remove":
manipulate.Remove(pos, 1);
manipulate.Insert(0, '0');
break;
case "insert":
manipulate.Remove(0, 1);
manipulate.Insert(pos, '1');
break;
}
}
ulong result = Convert.ToUInt64(manipulate.ToString(), 2);
Console.WriteLine(result);
}
示例15: Main
static void Main()
{
string s;
int inputLines = int.Parse(Console.ReadLine());
int desiredWidth = int.Parse(Console.ReadLine());
StringBuilder sb = new StringBuilder();
for (int i = 0; i < inputLines; i++)
{
s = Console.ReadLine();
sb.Append(s.Trim() + " ");
}
sb.Remove(sb.Length - 1, 1);
string[] sWords = sb.ToString().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
List<string> words = new List<string>(sWords);
do
{
sb.Clear();
sb.Append(words[0]);
int currentWord = 1;
while (sb.Length < desiredWidth && currentWord < words.Count)
{
sb.Append(" " + words[currentWord]);
currentWord++;
}
if (sb.Length > desiredWidth)
{
sb.Remove(sb.Length - words[currentWord - 1].Length - 1, words[currentWord - 1].Length + 1);
currentWord--;
}
if (sb.Length == desiredWidth || currentWord == 1)
{
Console.WriteLine(sb);
words.RemoveRange(0, currentWord);
continue;
}
int spacecount = currentWord - 1;
int sizeOfSpaces = (desiredWidth - sb.Length + spacecount) / spacecount; // / (currentWord - 1)
int numOfLongSpaces = (desiredWidth - sb.Length + spacecount) % spacecount;
sb.Clear();
sb.Append(words[0]);
for (int i = 1; i <= spacecount; i++)
{
if (i <= numOfLongSpaces)
sb.Append(" ");
sb.Append(new string(' ',sizeOfSpaces) + words[i]);
}
Console.WriteLine(sb);
words.RemoveRange(0, currentWord);
} while (words.Count > 0);
}