commonhelper 通用类:计时器、数组去重、自动生成日志编号、生成随机数、处理字符串
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
namespace Infrastructure
{
/// <summary>
/// 常用公共类
/// </summary>
public class CommonHelper
{
#region Stopwatch计时器
/// <summary>
/// 计时器开始
/// </summary>
/// <returns></returns>
public static Stopwatch TimerStart()
{
Stopwatch watch = new Stopwatch();
watch.Reset();
watch.Start();
return watch;
}
/// <summary>
/// 计时器结束
/// </summary>
/// <param name="watch"></param>
/// <returns></returns>
public static string TimerEnd(Stopwatch watch)
{
watch.Stop();
double costtime = watch.ElapsedMilliseconds;
return costtime.ToString();
}
#endregion
#region 删除数组中的重复项
/// <summary>
/// 删除数组中的重复项
/// </summary>
/// <param name="values"></param>
/// <returns></returns>
public static string[] RemoveDup(string[] values)
{
List<string> list = new List<string>();
for (int i = 0; i < values.Length; i++)//遍历数组成员
{
if (!list.Contains(values[i]))
{
list.Add(values[i]);
};
}
return list.ToArray();
}
#endregion
#region 自动生成日期编号
/// <summary>
/// 自动生成编号 201008251145409865
/// </summary>
/// <returns></returns>
public static string CreateNo()
{
Random random = new Random();
string strRandom = random.Next(1000, 10000).ToString(); //生成编号
string code = DateTime.Now.ToString("yyyyMMddHHmmss") + strRandom;//形如
return code;
}
#endregion
#region 生成0-9随机数
/// <summary>
/// 生成0-9随机数
/// </summary>
/// <param name="codeNum">生成长度</param>
/// <returns></returns>
public static string RndNum(int codeNum)
{
StringBuilder sb = new StringBuilder(codeNum);
Random rand = new Random();
for (int i = 1; i < codeNum + 1; i++)
{
int t = rand.Next(9);
sb.AppendFormat("{0}", t);
}
return sb.ToString();
}
#endregion
#region 删除最后一个字符之后的字符
/// <summary>
/// 删除最后结尾的一个逗号
/// </summary>
public static string DelLastComma(string str)
{
return str.Substring(0, str.LastIndexOf(","));
}
/// <summary>
/// 删除最后结尾的指定字符后的字符
/// </summary>
public static string DelLastChar(string str, string strchar)
{
return str.Substring(0, str.LastIndexOf(strchar));
}
/// <summary>
/// 删除最后结尾的长度
/// </summary>
/// <param name="str"></param>
/// <param name="Length"></param>
/// <returns></returns>
public static string DelLastLength(string str, int Length)
{
if (string.IsNullOrEmpty(str))
return "";
str = str.Substring(0, str.Length - Length);
return str;
}
#endregion
}
}
commonhelper 通用类:计时器、数组去重、自动生成日志编号、生成随机数、处理字符串的更多相关文章
- Memcached通用类(基于enyim.com Memcached Client)
一.如果用官方提供的方法,在web.config里面配置好了各个参数和服务器IP.如下图: <?xml version="1.0"?> <configuratio ...
- C#---数据库访问通用类、Access数据库操作类、mysql类 .[转]
原文链接 //C# 数据库访问通用类 (ADO.NET)using System;using System.Collections.Generic;using System.Text;using Sy ...
- C#---数据库访问通用类、Access数据库操作类、mysql类 .
//C# 数据库访问通用类 (ADO.NET)using System;using System.Collections.Generic;using System.Text;using System. ...
- 我写的一个ExcelHelper通用类,可用于读取或生成数据
读取或生成EXCEL数据的方法有很多,一般常见的有: 1.通过OFFICE EXCEL组件,优点:读取与生成EXCEL文件方便,缺点:服务器上必须安装OFFICE软件,且进程无法及时释放 2.通过第三 ...
- 页面上有3个输入框:分别为max,min,num;三个按钮:分别为生成,排序,去重;在输入框输入三个数字后,先点击生成按钮,生成一个数组长度为num,值为max到min之间的随机整数点击排序,对当前数组进行排序,点击去重,对当前数组进行去重。 每次点击之后使结果显示在控制台
<!DOCTYPE html> <html> <head> <!-- 页面上有3个输入框:分别为max,min,num:三个按钮:分别为生成,排序,去重: 在 ...
- JavaScript常见的五种数组去重的方式
▓▓▓▓▓▓ 大致介绍 JavaScript的数组去重问题在许多面试中都会遇到,现在做个总结 先来建立一个数组 var arr = [1,2,3,3,2,'我','我',34,'我的',NaN,NaN ...
- 关于数组去重的几种方法-------javascript描述
第一种方法:借助json对象来实现,若json对象中无该属性则添加,否则不添加,最后返回json对象的属性,时间复杂度为O(n) function deleteArrayRepeat(arr) { v ...
- poi导出excel通用类
一.关键的通用类public class PoiExportUtils { private static HSSFWorkbook workBook; public PoiExportUtils ...
- ES6的新方法实现数组去重
ES6里新添加了两个很好用的东西,set和Array.from. set是一种新的数据结构,它可以接收一个数组或者是类数组对象,自动去重其中的重复项目. 在这我们可以看见,重复的项目已经被去掉了,包括 ...
随机推荐
- 操作实践:maven工程查找工程中多余的jar包
声明:迁移自本人CSDN博客https://blog.csdn.net/u013365635 版本迭代过程中对jar的依赖可能会产生变化,一些本不必再依赖的jar包可以因为没有清除而依然留在版本的发布 ...
- 干货 | 京东技术中台的Flutter实践之路
在 2019 年,Flutter 推出了多个正式版本,支持的终端越来越多,使用的项目也越来越多.Flutter 正在经历从小范围尝鲜到大面积应用的过程,越来越多的研发团队加入到 Flutter 的学习 ...
- WGAN将数值限制在一定范围内 Python代码 tf.clip_by_value(p, -0.01, 0.01))
tf.clip_by_value(p, min, max)) 运用的是交叉熵而不是二次代价函数. 功能:可以将一个张量中的数值限制在(min,max)内.(可以避免一些运算错误:可以保证在进行lo ...
- Qt在vs2010下的配置
https://blog.csdn.net/chenbang110/article/details/7607250 首先不要使用中文目录, 1 下载Qt的安装包和VS2010的Qt插件 2. 安装Qt ...
- Ubuntu18.04 有线无法正常上网(请读完全文再进行操作)
电脑Windows10+Ubuntu18.04双系统,一直都没问题,前段时间突然在Ubuntu系统下有线连接失败,但是在Windows下可以正常上网. 今天尝试进行了修复. 在终端通过ifconfig ...
- GitHub的学习和使用
大二寒假阶段: 今天初学了GitHub,并下载了git base,在如下大佬给的链接下并完成了新用户的注册以及项目的上传学习. 网站的新用户注册界面: https://g ...
- nouveau :failed to create kernel chanel,-22
一:錯誤描述:今天在重啓 Ubuntu 的過程中,出現下圖的 grub 選項,系統重啓/開機之後出現以下畫面,然後選擇 Ubuntu 之後黑屏,提示錯誤:nouveau :failed to crea ...
- PAT Advanced 1084 Broken Keyboard (20) [Hash散列]
题目 On a broken keyboard, some of the keys are worn out. So when you type some sentences, the charact ...
- python os.path.dirname() abspath()
测试文件的名称 path_test.py 先确定文件目录 (my_flask3) python@ubuntu:~/Desktop/flask_news_pro$ python path_test.py ...
- CocoaPods-Alcatraz插件
Alcatraz:Xcode的插件管理工具,可通过它添加CocoaPods插件 下载地址:https://github.com/alcatraz/Alcatraz 建议: 不提倡通过终端命令下载Alc ...