SO - String ranges

CSharp · Console

/Program.cs

using System;
					
public class Program
{
	public static void Main()
	{
		Console.WriteLine("H".FirstLastChars());
	}	

}

public static class StringExtentions {
    public static string FirstLastChars(this string str)
    {
	   if(str.Length < 4) return str[..];
       return str[..2] + str[^2..];
    }
}
;