博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
一些简单有用的方法合集
阅读量:4677 次
发布时间:2019-06-09

本文共 3452 字,大约阅读时间需要 11 分钟。

///         /// 处理过长的显示字符串,只显示前几个字符,后面加上“...”        ///         ///         /// 要处理的字符串        /// 需要的长度        /// 
public static string GetSeveralChar(string str, int size) { return Encoding.Default.GetBytes(str).Length > size ? Encoding.Default.GetString(Encoding.Default.GetBytes(str).Take(size).ToArray()).Replace("?", String.Empty) + "..." : str; } /// /// 注册JS /// /// /// /// public static void RegisterStartupScript(System.Web.UI.Page page, string Method) { page.ClientScript.RegisterStartupScript(page.GetType(), DateTime.Now.ToString(), ""); } /// /// 根据数字得到二进制的字符串 /// /// /// ///
public static string GetBlobFromNum(int num) { int len = sizeof(int) * 8; StringBuilder str = new StringBuilder(); int exmple = 1 << len - 1; int tmp = num; for (int i = 0; i < len; i++) { str.Append((tmp & exmple) == 0 ? "0" : "1"); tmp <<= 1; } return str.ToString().Substring(str.ToString().Length - 4); } /// /// 根据二进制获取数字集合 /// /// /// ///
public static string GetNumArrayByBlob(string blob) { string NumArray = string.Empty; for (int i = 0; i < blob.Length; i++) { if (blob.Substring(i, 1) == "1") { NumArray = string.IsNullOrEmpty(NumArray) ? Get2ndPowerNum(blob.Length - i - 1).ToString() : NumArray + "," + Get2ndPowerNum(blob.Length - i - 1).ToString(); } } return NumArray; } /// /// 计算2的N次方的方法 /// /// /// ///
public static int Get2ndPowerNum(int lenth) { return lenth == 0 ? 1 : 2 * Get2ndPowerNum(lenth - 1); } /// /// 将List转换为字符串 /// /// ///
public static string GetListCollectionByStr(List
coll) { string result = string.Empty; for (int i = 0; i < coll.Count; i++) { result = string.IsNullOrEmpty(result) ? coll[i] : result + "," + coll[i]; } return result; } ///
/// 从数组中随机取出多个不重复的项 /// 作者:刘仁和 /// ///
///
///
public static IList
getListItems(IList
list, int num) { //新建一个泛型列表,将传入的列表复制过来,用于运算,而不要直接操作传入的列表; //这样写是引用复制,不对啦 //IList
temp_list = list; //另外这样写也要注意,也不是深度复制 IList
temp_list = new List
(list); //取出的项,保存在此列表 IList
return_list = new List
(); //Random random = new Random(unchecked((int)DateTime.Now.Ticks)); Random random = new Random(); for (int i = 0; i < num; i++) { //判断如果列表还有可以取出的项,以防下标越界 if (temp_list.Count > 0) { //在列表中产生一个随机索引 int arrIndex = random.Next(0, temp_list.Count); //将此随机索引的对应的列表元素值复制出来 return_list.Add(temp_list[arrIndex]); //然后删掉此索引的列表项 temp_list.RemoveAt(arrIndex); } else { //列表项取完后,退出循环,比如列表本来只有10项,但要求取出20项. break; } } return return_list; }

 

转载于:https://www.cnblogs.com/xue632777974/archive/2013/02/26/2933910.html

你可能感兴趣的文章
1.7 节点进行排序显示
查看>>
web最佳实践
查看>>
spring 集成shiro 之 自定义过滤器
查看>>
验证密码不允许有连续三位重复的正则表达式
查看>>
python 中对list去重
查看>>
Mono Libgdiplus库
查看>>
js模糊查询案例
查看>>
c语言基础知识要点
查看>>
Android模拟器无法上网访问网络失败解决办法
查看>>
node启动时, listen EADDRINUSE 报错;
查看>>
vue学习链接
查看>>
Systemd 初始化进程
查看>>
【C#学习笔记】文本复制到粘贴板
查看>>
Windows store 验证你的 URL http:// 和 https:// ms-appx:/// ms-appdata:///local
查看>>
python全栈开发_day7_字符编码,以及文件的基本读取
查看>>
js 验证码 倒计时60秒
查看>>
C#基础
查看>>
ASP.NET Core MVC 2.x 全面教程_ASP.NET Core MVC 15. 用户管理
查看>>
杭电3466————DP之01背包(对状态转移方程的更新理解)
查看>>
JSP页面中的精确到秒的时间控件
查看>>