C
C#17mo ago
Juliandyce

❔ Stringbuilder remove

i have problem with remove in the following program: public class Program11 {
static void Main(string[] args) { StringBuilder sb = new StringBuilder("Hello World!", 50); //"Hallo Welt! start String //50 maximale Länge des Strings sb.Append(" How are u?"); // string hinten anfügen sb.AppendLine(); sb.AppendLine("I am fine!"); //string hinten anfügen zeilenumbruch sb.Insert(0, ":) ");

Console.WriteLine(sb.ToString()); sb.Remove(9, 14); Console.WriteLine(sb.ToString()); } }
} I wanna remove World witch should go from 9-14: output before remove; 🙂 Hello World! How are u? I am fine! output after remove: 🙂 Hello u? I am fine!
8 Replies
Juliandyce
JuliandyceOP17mo ago
":)" when i compiling it
TheBoxyBear
TheBoxyBear17mo ago
Check the indexes, keep in mind the line terminator characters added with AppendLine
Juliandyce
JuliandyceOP17mo ago
how do i check what is the terminator character
TheBoxyBear
TheBoxyBear17mo ago
Either \n or \r\n Just add the result to a string variable and add that variable to a Watch or just add "sb.ToString()" to the watch Watch displays the string as is on a single line with special characters as their escape form (backslash)
Juliandyce
JuliandyceOP17mo ago
what is the watch
cap5lut
cap5lut17mo ago
//50 maximale Länge des Strings
note that the 50 constructor parameter is not the maximum capacity of the StringBuilder but it's initial capacity which line separator (and thus its length) is used is specified by Environment.NewLine from the System namespace watch is a debugger feature, its a table where u can add variables/expressions, which then shows their values as well basically like
name | value
------------
x | 5
y | 15
str | "hi"
name | value
------------
x | 5
y | 15
str | "hi"
I wanna remove World witch should go from 9-14:
also check what the parameters for StringBuilder.Remove() are... the latter is not the end index 😉 btw ur commenting style is also a bit weird. basically everyone else writes the comment above the code they want to give a comment for ;p
TheBoxyBear
TheBoxyBear17mo ago
That or beside the line foo(); // do foo
Accord
Accord17mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server