从我的StringBuilder删除角色 [英] Removing a character from my stringbuilder

查看:165
本文介绍了从我的StringBuilder删除角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下字符串助洗剂msrtResult,这是相当长的:

I am having the following string builder as msrtResult, which is quite long:

mstrResult.Append(rtbResult.Text).Append("})})" + Environment.NewLine)

如何删除最后一个 从现在mstrResult? (这是在mstrResult的中间,因为我追加字符串到它,它不整串的最后一个字符)
我应该加入新行之前做到这一点。
谢谢

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

推荐答案

您可以只减少长度缩短字符串(C#):

You can just decrease the length to shorten the string (C#):

mstrResult.Length -= 1;



编辑:

在更新你之后问题,我想我知道你想要什么:)这个怎么样:

After you updated you question, I think I know what you want :) How about this:

mstrResult.Append(rtbResult.Text).Append("})})" + Environment.NewLine);
var index = mstrResult.ToString().LastIndexOf(',');
if (index >= 0)
    mstrResult.Remove(index, 1);

这篇关于从我的StringBuilder删除角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆