删除字符串的最后一个字符 [英] Delete last char of string

查看:135
本文介绍了删除字符串的最后一个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个链接到数据库的列表中检索了大量信息。

I am retrieving a lot of informations in a list, linked to a Database .

我想要创建一个组字符串,网站。

I want to create a string of groups, for someone who is connected to the website.

我用它来测试...但这不是动态的,所以真的很糟糕:

I use this to test ... But this is not dynamic so really bad :

string strgroupids =6;

string strgroupids = "6";

现在我想使用这个。但返回的字符串类似于1,2,3,4,5,

I want to use this now . But the string returned is something like 1,2,3,4,5,

        //groupIds.ForEach((g) =>
        //{
        //    strgroupids = strgroupids  + g.ToString() + ",";
        //    strgroupids.TrimEnd(',');
        //});

        //strgroupids.TrimEnd(new char[] { ',' });

我要删除,后5,但它绝对不工作..
有人帮助我?

I want to delete the , after the 5 but it's definitely not working .. Can someone help me?

非常感谢。

推荐答案

strgroupids = strgroupids.Remove(strgroupids.Length - 1);

MSDN:


String.Remove(Int32):

从指定的
位置开始,并从最后一个位置开始删除此字符串中的所有字符

Deletes all the characters from this string beginning at a specified position and continuing through the last position

这篇关于删除字符串的最后一个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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