VB string functions in C#
Just in case if anyone needs it.
//-----------------------------------------------------------------------
// <copyright file="Strings.cs" company="devqueries">
// Author: Neal Gabriel
// No rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace Helper
{
using System;
/// <summary>
/// Strings functions avialable in VB
/// </summary>
public class Strings
{
/// <summary>
/// Left of string
/// </summary>
/// <param name="param">String param</param>
/// <param name="length">Legnth is pulled out from left of the string</param>
/// <returns>String that is pulled out</returns>
public static string Left(string param, int length)
{
return param.Substring(0, length);
}
/// <summary>
/// Right of string
/// </summary>
/// <param name="param">String param</param>
/// <param name="length">Left to tbe pulled from right</param>
/// <returns>String the is pulled out</returns>
public static string Right(string param, int length)
{
return param.Substring(param.Length - length, length);
}
/// <summary>
/// Mid of string
/// </summary>
/// <param name="param">String param</param>
/// <param name="startIndex">Start index to be pulled</param>
/// <param name="length">Length from the start index</param>
/// <returns>String that is pulled out</returns>
public static string Mid(string param, int startIndex, int length)
{
return param.Substring(startIndex, length);
}
/// <summary>
/// Mid of string
/// </summary>
/// <param name="param">String param</param>
/// <param name="startIndex">Start index to be pulled</param>
/// <returns>String that is pulled out</returns>
public static string Mid(string param, int startIndex)
{
return param.Substring(startIndex);
}
/// <summary>
/// Get content in string
/// </summary>
/// <param name="original">String param</param>
/// <param name="containsKey">Contains key</param>
/// <returns>Index of the string</returns>
public static int InStr(string original, string containsKey)
{
return original.IndexOf(containsKey, StringComparison.Ordinal) > -1 ? original.IndexOf(containsKey, StringComparison.Ordinal) : 0;
}
/// <summary>
/// Format datetime
/// </summary>
/// <param name="param">Datetime param</param>
/// <param name="format">Format of datatime object</param>
/// <returns>Formatted datetime as string</returns>
public static string Format(DateTime param, string format)
{
return param.ToString(format);
}
/// <summary>
/// Get length of string
/// </summary>
/// <param name="param">String param</param>
/// <returns>Length of string</returns>
public static int Len(string param)
{
return param == null ? 0 : param.Length;
}
}
}
//-----------------------------------------------------------------------
// <copyright file="Strings.cs" company="devqueries">
// Author: Neal Gabriel
// No rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace Helper
{
using System;
/// <summary>
/// Strings functions avialable in VB
/// </summary>
public class Strings
{
/// <summary>
/// Left of string
/// </summary>
/// <param name="param">String param</param>
/// <param name="length">Legnth is pulled out from left of the string</param>
/// <returns>String that is pulled out</returns>
public static string Left(string param, int length)
{
return param.Substring(0, length);
}
/// <summary>
/// Right of string
/// </summary>
/// <param name="param">String param</param>
/// <param name="length">Left to tbe pulled from right</param>
/// <returns>String the is pulled out</returns>
public static string Right(string param, int length)
{
return param.Substring(param.Length - length, length);
}
/// <summary>
/// Mid of string
/// </summary>
/// <param name="param">String param</param>
/// <param name="startIndex">Start index to be pulled</param>
/// <param name="length">Length from the start index</param>
/// <returns>String that is pulled out</returns>
public static string Mid(string param, int startIndex, int length)
{
return param.Substring(startIndex, length);
}
/// <summary>
/// Mid of string
/// </summary>
/// <param name="param">String param</param>
/// <param name="startIndex">Start index to be pulled</param>
/// <returns>String that is pulled out</returns>
public static string Mid(string param, int startIndex)
{
return param.Substring(startIndex);
}
/// <summary>
/// Get content in string
/// </summary>
/// <param name="original">String param</param>
/// <param name="containsKey">Contains key</param>
/// <returns>Index of the string</returns>
public static int InStr(string original, string containsKey)
{
return original.IndexOf(containsKey, StringComparison.Ordinal) > -1 ? original.IndexOf(containsKey, StringComparison.Ordinal) : 0;
}
/// <summary>
/// Format datetime
/// </summary>
/// <param name="param">Datetime param</param>
/// <param name="format">Format of datatime object</param>
/// <returns>Formatted datetime as string</returns>
public static string Format(DateTime param, string format)
{
return param.ToString(format);
}
/// <summary>
/// Get length of string
/// </summary>
/// <param name="param">String param</param>
/// <returns>Length of string</returns>
public static int Len(string param)
{
return param == null ? 0 : param.Length;
}
}
}
Comments
Post a Comment