Reputation: 35
Hi I have a string maybe like this
string str="user1,user2,user3,user4,user5,user6";
I want remove all of string at last ,
then the str became user6
.
How can I do it use c#
Upvotes: 1
Views: 61
Reputation: 24619
Try:
string newStr = str.Substring(str.LastIndexOf(",") + 1));
or add using System.Linq;
and use:
string newStr = str.Split(',').Last();
Upvotes: 4
Reputation: 17605
It could be done using Linq as follows.
string Result
= str.Split(new char[]{','}, StringSplitOptions.RemoveEmptyEntries).Last();
Upvotes: 0