C
C#4mo ago
Aki

✅ Where does the extra linebreak come from (StringBuilder)?

stringBuilder.AppendLine("\t<tr>"); // StringBuilder

foreach (string cell in cells)
{
stringBuilder
.Append("\t\t<td>")
.Append(cell)
.AppendLine("</td>");
}

stringBuilder.AppendLine("\t</tr>");
stringBuilder.AppendLine("\t<tr>"); // StringBuilder

foreach (string cell in cells)
{
stringBuilder
.Append("\t\t<td>")
.Append(cell)
.AppendLine("</td>");
}

stringBuilder.AppendLine("\t</tr>");
expected result:
<tr>
<td>String</td>
<td>name</td>
<td></td>
<td></td>
</tr>
<tr>
<td>String</td>
<td>name</td>
<td></td>
<td></td>
</tr>
actual result:
<tr>

<td>String</td>

<td>name</td>

<td></td>

<td></td>

</tr>
<tr>

<td>String</td>

<td>name</td>

<td></td>

<td></td>

</tr>
result shown on screenshot to show new line characters.
No description
15 Replies
MODiX
MODiX4mo ago
leowest
REPL Result: Success
var sb = new StringBuilder();
sb.AppendLine("\t<tr>");
var cells = new string[] { "id", "name", "age" };
foreach (string cell in cells)
{
sb.AppendLine($"\t\t<td>{cell}</td>");
}
sb.AppendLine("\t</tr>");
sb.ToString()
var sb = new StringBuilder();
sb.AppendLine("\t<tr>");
var cells = new string[] { "id", "name", "age" };
foreach (string cell in cells)
{
sb.AppendLine($"\t\t<td>{cell}</td>");
}
sb.AppendLine("\t</tr>");
sb.ToString()
Result: string
<tr>
<td>id</td>
<td>name</td>
<td>age</td>
</tr>
<tr>
<td>id</td>
<td>name</td>
<td>age</td>
</tr>
Quoted by
<@1102729783969861782> from #bot-spam (click here)
Compile: 372.542ms | Execution: 45.577ms | React with ❌ to remove this embed.
leowest
leowest4mo ago
so without more context on what else is touching that code hard to say
Aki
AkiOP4mo ago
nothing, that is an empty string builder that is then untouched further, no processing, its just written into a text file
leowest
leowest4mo ago
I mean without seeing your code that is using it not much I can say unhappily. sometimes minimal things can make a difference
leowest
leowest4mo ago
No description
leowest
leowest4mo ago
that is what it produces untoched and saving to a file
leowest
leowest4mo ago
No description
leowest
leowest4mo ago
unhappily that does not show me how its being used, so same I said above remains
leowest
leowest4mo ago
all I can do is show u that it works as intended as I did above
Aki
AkiOP4mo ago
im unsure what you are looking for oh. you were right. i do mess it up. im calling the wrong file saving thing and its trying to convert it to yaml format ;-; i named my method wrong and confused myself with it
leowest
leowest4mo ago
glad u figured it out sometimes it be like that something very small causes the issue and we think the problem is somewhere else
MODiX
MODiX4mo ago
If you have no further questions, please use /close to mark the forum thread as answered
Want results from more Discord servers?
Add your server