124 lines
4.3 KiB
C#
124 lines
4.3 KiB
C#
//-----------------------------------------------------------------------
|
|
// <copyright file="DefaultStringManager.cs" company="BTU/IIT">
|
|
// Company copyright tag.
|
|
// </copyright>
|
|
// <author>stubbfel</author>
|
|
// <sience>06.06.2013</sience>
|
|
//----------------------------------------------------------------------
|
|
namespace CampusAppWPortalLib8.Utility
|
|
{
|
|
using System;
|
|
using System.Text.RegularExpressions;
|
|
using CampusAppWPortalLib8.Resources;
|
|
|
|
/// <summary>
|
|
/// Class provides some special StringMethods
|
|
/// </summary>
|
|
public class DefaultStringManager
|
|
{
|
|
#region Members
|
|
|
|
/// <summary>
|
|
/// Patter for Html-Tags
|
|
/// </summary>
|
|
private static readonly string HtmlTagPattern = "<.*?>";
|
|
|
|
/// <summary>The mail valid regular expression.</summary>
|
|
private static readonly string EMailValidRegex = @"^(?("")(""[^""]+?""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9]{2,17}))$";
|
|
|
|
#endregion
|
|
|
|
#region Methods
|
|
|
|
/// <summary>
|
|
/// Method removes Html-Tag of a String
|
|
/// </summary>
|
|
/// <param name="inputString">String with Html-Tags</param>
|
|
/// <returns>String without Html-Tags</returns>
|
|
public static string StripHTML(string inputString)
|
|
{
|
|
return Regex.Replace(inputString, DefaultStringManager.HtmlTagPattern, string.Empty);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Method add an Newline to a string
|
|
/// </summary>
|
|
/// <param name="str">input string</param>
|
|
/// <returns>input string + newline</returns>
|
|
public static string AddNewLine(string str)
|
|
{
|
|
return str.ToString() + "\n";
|
|
}
|
|
|
|
/// <summary>Method remove(TrimEND!) an Newline to a string.</summary>
|
|
/// <remarks>Stubbfel, 12.09.2013.</remarks>
|
|
/// <param name="str">input string.</param>
|
|
/// <returns>input string - newline.</returns>
|
|
public static string RemoveNewLine(string str)
|
|
{
|
|
return str.TrimEnd('\n');
|
|
}
|
|
|
|
/// <summary>Query if 'strIn' is valid email.</summary>
|
|
/// <remarks>Stubbfel, 04.09.2013.</remarks>
|
|
/// <param name="strIn">The in.</param>
|
|
/// <returns>true if valid email, false if not.</returns>
|
|
public static bool IsValidEmail(string strIn)
|
|
{
|
|
// Return true if strIn is in valid e-mail format.
|
|
try
|
|
{
|
|
return Regex.IsMatch(
|
|
strIn,
|
|
DefaultStringManager.EMailValidRegex,
|
|
RegexOptions.IgnoreCase);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// <summary>Creates uni telefon number.</summary>
|
|
/// <remarks>Stubbfel, 04.09.2013.</remarks>
|
|
/// <param name="input">The input.</param>
|
|
/// <returns>The new uni telefon number.</returns>
|
|
public static string CreateUniTelefonNumber(string input)
|
|
{
|
|
string result = null;
|
|
if (input.Length < 5)
|
|
{
|
|
result = Constants.UniCBTelPrefix + input.TrimStart('0');
|
|
}
|
|
else
|
|
{
|
|
result = input;
|
|
}
|
|
|
|
Regex regexObj = new Regex(@"[^\d]");
|
|
result = regexObj.Replace(result.TrimStart('0'), string.Empty);
|
|
result = Constants.DeTelPrefix + result;
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Method create from a long string a short string
|
|
/// </summary>
|
|
/// <param name="longStr">the long input String</param>
|
|
/// <param name="maxLenght">max length of the short string</param>
|
|
/// <param name="suffix">(optional) suffix which added to the short string, when long string has to be cut</param>
|
|
/// <returns>the shorted string</returns>
|
|
public static string ToShortString(string longStr, int maxLenght, string suffix = "")
|
|
{
|
|
string shortStr = longStr;
|
|
if (shortStr.Length > maxLenght)
|
|
{
|
|
shortStr = shortStr.Substring(0, maxLenght) + suffix;
|
|
}
|
|
|
|
return shortStr;
|
|
}
|
|
#endregion
|
|
}
|
|
}
|