Skip to main content
added 92 characters in body
Source Link
p.s.w.g
  • 149.6k
  • 31
  • 307
  • 339

In addition to lazyberezovsky's answer, you can also do this:

var input = "ICMS_MG-PR-RJ-RS-SC"; var states = input.Split('_')[1].Split('-').ToList(); 

Or this

var states = input.Split('_', '-').Skip(1).ToList(); 

Or this

var states = input.Substring(input.IndexOf('_') + 1).Split('-').ToList(); 

Note, however, unless you really need to be able to access each element by index, there's probably no need to call ToList. If you can settle for an IEnumerable<string>, you probably should.

In addition to lazyberezovsky's answer, you can also do this:

var input = "ICMS_MG-PR-RJ-RS-SC"; var states = input.Split('_')[1].Split('-').ToList(); 

Or this

var states = input.Split('_', '-').Skip(1).ToList(); 

In addition to lazyberezovsky's answer, you can also do this:

var input = "ICMS_MG-PR-RJ-RS-SC"; var states = input.Split('_')[1].Split('-').ToList(); 

Or this

var states = input.Split('_', '-').Skip(1).ToList(); 

Or this

var states = input.Substring(input.IndexOf('_') + 1).Split('-').ToList(); 

Note, however, unless you really need to be able to access each element by index, there's probably no need to call ToList. If you can settle for an IEnumerable<string>, you probably should.

Source Link
p.s.w.g
  • 149.6k
  • 31
  • 307
  • 339

In addition to lazyberezovsky's answer, you can also do this:

var input = "ICMS_MG-PR-RJ-RS-SC"; var states = input.Split('_')[1].Split('-').ToList(); 

Or this

var states = input.Split('_', '-').Skip(1).ToList();