You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

63 lines
1.7 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Wood.Util
{
public class TextHelper
{
/// <summary>
/// 获取默认值
/// </summary>
/// <param name="value"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static string GetCustomValue(string value, string defaultValue)
{
if (string.IsNullOrEmpty(value))
{
return defaultValue;
}
else
{
return value;
}
}
/// <summary>
/// 截取指定长度的字符串
/// </summary>
/// <param name="value"></param>
/// <param name="length"></param>
/// <returns></returns>
public static string GetSubString(string value, int length, bool ellipsis = false)
{
if (string.IsNullOrEmpty(value))
{
return value;
}
if (value.Length > length)
{
value = value.Substring(0, length);
if (ellipsis)
{
value += "...";
}
}
return value;
}
/// <summary>
/// 字符串转指定类型数组
/// </summary>
/// <param name="value"></param>
/// <param name="split"></param>
/// <returns></returns>
public static T[] SplitToArray<T>(string value, char split)
{
T[] arr = value.Split(new string[] { split.ToString() }, StringSplitOptions.RemoveEmptyEntries).CastSuper<T>().ToArray();
return arr;
}
}
}