Left Sring Function in C Sharp

Left Sring Function in C Sharp

In C# non esiste una funzione di sistema per recuperare la Left di una stringa.

Ecco lo snippet:

public static string Left(string text, int length) { if (length < 0) throw new ArgumentOutOfRangeException("length", length, "length must be > 0"); else if (length == 0 || text.Length == 0) return ""; else if (text.Length <= length) return text; else return text.Substring(0, length); }

Leave a Reply

Your email address will not be published. Required fields are marked *

Are you human? Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.