C# Equivalent für VB's "Left" Funktion

Tags: .NET

public static string Left(string strText, int intLength)
{
	try
	{
		if (intLength < 0)
			throw new ArgumentOutOfRangeException("Length", intLength, "Length must be > 0");
		else if (intLength == 0 || strText.Length == 0)
			return "";
		else if (strText.Length <= intLength)
			return strText;
		else
			return strText.Substring(0, intLength);
	}
	catch {}
}
Add a Comment