diff Lang/StringManipulation.cs @ 0:961030992bd2

Initial commit of IBBoard libraries
author IBBoard <dev@ibboard.co.uk>
date Fri, 19 Dec 2008 11:13:48 +0000
parents
children 0352fa33ee8f
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Lang/StringManipulation.cs	Fri Dec 19 11:13:48 2008 +0000
@@ -0,0 +1,44 @@
+using System;
+using System.Text;
+
+namespace IBBoard.Lang
+{
+	/// <summary>
+	/// Summary description for StringManipulation.
+	/// </summary>
+	public class StringManipulation
+	{		
+		private static Encoding utf8;
+
+		static StringManipulation()
+		{
+			utf8 = Encoding.UTF8;
+		}
+
+		public static byte[] StringToBytes(string str)
+		{
+			return utf8.GetBytes(str);
+		}
+
+		public static string RemoveFromLast(string stringToTrim, char removeFrom)
+		{
+			return stringToTrim.Substring(0, stringToTrim.LastIndexOf(removeFrom));
+		}
+
+		public static string CutToLength(string stringToShorten, int length)
+		{
+			int strLength = stringToShorten.Length;
+
+			if (length >= strLength-2)
+			{
+				return stringToShorten;
+			}
+			else
+			{
+				int diff = (strLength - length) / 2;
+				int halfLength = strLength / 2;
+				return stringToShorten.Substring(0, halfLength - diff)+"..."+stringToShorten.Substring(halfLength + diff);
+			}
+		}
+	}
+}