Reputation: 1981
I need to split a string on the last comma. I have this which works, if there is only one comma
var ident = identNumbers.Split(',').ToList();
my string is being formatted using Jquery/CSS and is derived from a JSON string, which doesn't contain any new line characters.
the string looks like:
Special Interest Entity (SIE) / Sanctions Lists / State Owned Company,Special Interest Entity (SIE) / Enhanced Country Risk / State Owned Company
and i need to end up with a list that looks like this:
Upvotes: 0
Views: 113
Reputation: 101701
I think, you need something like this:
var input = "foo, bar, sample1, sample2 sample3";
var last = input.LastIndexOf(',');
var result = new[] {input.Substring(0, last), input.Substring(last+1).Trim()};
result
contains two elements: "foo, bar, sample1"
and "sample2 sample3"
Upvotes: 2