如何从字符串的最后一个索引中删除',' [英] How to remove ',' from last index of the string

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

问题描述

如何从字符串的最后一个索引中删除'',''

How to remove '','' from last index of the string

string text='Aluminium,Alternaria Tenius,Alcohol (ethyl alcohol),2-Hydroxyethyl,Beryllium,'


谢谢

推荐答案

使用字符串运算符LastIndexOfSubString Length 来获取不带最后一个.的字符串.
Use string operator LastIndexOf, SubString and Length to get the string without the last ,.


这和myString.Trim(new char[] {'',''}一样简单,但是您能考虑一下如何避免首先添加多余的逗号吗?

因此,请参阅 http://msdn.microsoft.com/en-us/library/d4tt83f9.aspx [ ^ ],但认为关于它.

请记住,字符串是不可变的,因此所有类似的字符串操作都意味着通过来回复制所有数据来创建全新的字符串.这就是System.Text.StringBuilder对于字符串操作更好的原因,但是如果您已经生成了需要修复的字符串,它对您没有太大帮助.首先尝试避免它.或者-如果性能不成问题,请忽略它并使用Trim.

—SA
This is as simple as myString.Trim(new char[] {'',''}, but can you rather think about how to avoid adding redundant comma in first place?

So, please see http://msdn.microsoft.com/en-us/library/d4tt83f9.aspx[^], but think about it.

Remember that strings are immutable, so all string operations like that mean creation of the brand new string with copying all the data back and forth. That''s why System.Text.StringBuilder is better for string manipulations, but it won''t help you much if you already produced the string which needs some fix. Try to avoid it in first place. Or — forget it and use Trim if performance is not an issue.

—SA




对于您的问题
Hi,

For your problem
text.Trim(',');



将解决您的问题.

谢谢
-Amit.



will resolve your issue.

thanks
-Amit.


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

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