I am having the following string builder as msrtResult, which is quite long:
mstrResult.Append(rtbResult.Text).Append("})})" + Environment.NewLine)
How can I remove the last "," from mstrResult Now? (it is in the middle of that mstrResult and it is not the last character of the whole string since I am appending strings to it) I should do it before adding the newline. Thanks
Use:
then call
Add a StringBuilder extension.
then invoke:
Try
You can just decrease the length to shorten the string (C#):
EDIT:
After you updated you question, I think I know what you want :) How about this:
To just remove the last character you appended use below: (This is VB but C should work similarly)
You can use
StringBuilder.Remove()
if you know the position of the character(s) you want to remove.I'd imagine that it would be easier not to add it in the first place.
Your updated question talks about removing the last comma character. I'm guessing you want to do this to avoid creating a message that looks like this:
You'd assemble this in a loop, iterating over an array. Usually you can write the loop so that you simply choose (e.g. with an if statement) not to add the command when you are in the final iteration of the loop.