source/Repid.Utility/Helper/StringHelper.cs
(开头部分) 6KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
namespace Repid.Utility.Helper
{
/// <summary>
/// 字符串处理
/// </summary>
public static class StringHelper
{
private static DateTime BaseTime = new DateTime(1970, 1, 1); //Unix起始时间
/// <summary>
/// 时间转时间戳
/// </summary>
/// <param name="time"></param>
/// <returns></returns>
public static long GetLongByDateTime(DateTime time)
{
return (time.Ticks - BaseTime.Ticks) / 10000000 - 8 * 60 * 60;
}
/// <summary>
/// 时间戳转时间
/// </summary>
/// <param name="time"></param>
/// <returns></returns>
public static DateTime GetDateTimeByLong(long time)
{
return BaseTime.AddTicks((time + 8 * 60 * 60) * 10000000);
}
/// <summary>
/// 裁剪指定长度文本(兼容中文)
/// </summary>
/// <param name="value">原文本</param>
/// <param name="length">指定长度</param>
/// <returns>裁剪后文本</returns>
public static string Cut(this string value, int length)
{
if (string.IsNullOrEmpty(value)) { return string.Empty; }
Regex regex = new Regex("[\u4e00-\u9fa5]+", RegexOptions.Compiled);
StringBuilder sb = new StringBuilder();
char[] stringChar = value.ToCharArray();
int nLength = 0; bool isCut = false;
for (int i = 0; i < stringChar.Length; i++)
{
if (regex.IsMatch((stringChar[i]).ToString()))
{
sb.Append(stringChar[i]); nLength += 2;
}
后面还有 126 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。