/////////////////////////////////////////////////////////////////////////////////////////////// // // This File is Part of the CallButler Open Source PBX (http://www.codeplex.com/callbutler // // Copyright (c) 2005-2008, Jim Heising // All rights reserved. // // Redistribution and use in source and binary forms, with or without modification, // are permitted provided that the following conditions are met: // // * Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation and/or // other materials provided with the distribution. // // * Neither the name of Jim Heising nor the names of its contributors may be // used to endorse or promote products derived from this software without specific prior // written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. // IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. // /////////////////////////////////////////////////////////////////////////////////////////////// using System; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; using System.Windows.Forms; using System.Xml; namespace WOSI.Utilities { public class StringUtils { public static string XmlEncodeString(string inputString) { XmlDocument xmlDoc = new XmlDocument(); XmlElement xmlElement = xmlDoc.CreateElement("Str"); xmlElement.InnerText = inputString; return xmlElement.InnerXml; } } }
Author: coder
Gets the string up to the maximum number of characters.
//Microsoft Public License (Ms-PL)
//http://visualizer.codeplex.com/license
using System;
using System.Collections.Generic;
namespace Redwerb.BizArk.Core.StringExt
{
///
///
public static class StringExt
{
///
///
///
///
///
public static string Max(this string str, int max)
{
return Max(str, max, false);
}
///
///
///
///
///
///
public static string Max(this string str, int max, bool ellipses)
{
if (str == null) return null;
if (str.Length <= max) return str; if (ellipses) return str.Substring(0, max - 3) + "..."; else return str.Substring(0, max); } } } [/csharp]
Shortcut for string.Format.
//Microsoft Public License (Ms-PL) //http://visualizer.codeplex.com/license using System; using System.Collections.Generic; namespace Redwerb.BizArk.Core.StringExt { /// <summary> /// Provides extension methods for strings. /// </summary> public static class StringExt { /// <summary> /// Shortcut for string.Format. /// </summary> /// <param name="str"></param> /// <param name="args"></param> /// <returns></returns> public static string Format(this string str, params object[] args) { if (str == null) return null; return string.Format(str, args); } } }
Truncates the string from left side
//Microsoft Public License (Ms-PL)
//http://visualizer.codeplex.com/license
using System;
using System.Collections.Generic;
namespace Redwerb.BizArk.Core.StringExt
{
///
///
public static class StringExt
{
///
///
///
///
///
public static string Left(this string str, int length)
{
if (str == null) return null;
if (str.Length <= length) return str;
return str.Substring(0, length);
}
}
}
[/csharp]
Gets the right side of the string.
//Microsoft Public License (Ms-PL)
//http://visualizer.codeplex.com/license
using System;
using System.Collections.Generic;
namespace Redwerb.BizArk.Core.StringExt
{
///
///
public static class StringExt
{
///
///
///
///
///
public static string Right(this string str, int length)
{
if (str == null) return null;
if (str.Length <= length) return str;
return str.Substring(str.Length - length);
}
}
}
[/csharp]
Determines if a string consists of all valid ASCII values.
//Microsoft Public License (Ms-PL) //http://visualizer.codeplex.com/license using System; using System.Collections.Generic; namespace Redwerb.BizArk.Core.StringExt { /// <summary> /// Provides extension methods for strings. /// </summary> public static class StringExt { /// <summary> /// Determines if a string consists of all valid ASCII values. /// </summary> /// <param name="str"></param> /// <returns></returns> public static bool IsAscii(this string str) { if (string.IsNullOrEmpty(str)) return true; foreach (var ch in str) if ((int)ch > 127) return false; return true; } } }
Splits the string into words (all white space is removed).
//Microsoft Public License (Ms-PL) //http://visualizer.codeplex.com/license using System; using System.Collections.Generic; namespace Redwerb.BizArk.Core.StringExt { /// <summary> /// Provides extension methods for strings. /// </summary> public static class StringExt { /// <summary> /// Splits the string into words (all white space is removed). /// </summary> /// <param name="str"></param> /// <returns></returns> public static string[] Words(this string str) { return str.Split(new char[] { }, StringSplitOptions.RemoveEmptyEntries); } } }