Skip to content
Advertisement

String Slicing in c# using intervals

In python there are ways that allow you to access the string using an interval(slicing):

Example Get the characters from position 2 to position 5 (not included):

JavaScript

Is there something similar in c#?

Advertisement

Answer

In C# 8.0 (or higher) you can use ranges, e.g

JavaScript

Or on old c# versions, Substring:

JavaScript

Finally, you can use Linq, but it’s overshoot here:

JavaScript
Advertisement