已阅读5页,还剩8页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
c# 操作字符串和图片转载 C#类实现字符串的公共操作二字符串过滤 收藏using System;using System.Drawing;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Text.RegularExpressions;using System.IO;using System.Drawing.Imaging;using System.Text;using System.Web.Security;namespace WeYyzyq.Comp / / 对一些字符串进行操作的类 / public class StringUtil private static string passWord; /加密字符串 / / 判断输入是否数字 / / 要判断的字符串 / static public bool VldInt(string num) #region try Convert.ToInt32(num); return true; catch return false; #endregion / / 返回文本编辑器替换后的字符串 / / 要替换的字符串 / static public string GetHtmlEditReplace(string str) #region return str.Replace(, ).Replace( , ).Replace(, ,).Replace(%, ).Replace(script,).Replace(.js,); #endregion / / 截取字符串函数 / / 所要截取的字符串 / 截取字符串的长度 / static public string GetSubString(string str, int num) #region return (str.Length num) ? str.Substring(0, num) + . : str; #endregion / / 过滤输入信息 / / 内容 / 最大长度 / public static string InputText(string text, int maxLength) #region text = text.Trim(); if (string.IsNullOrEmpty(text) return string.Empty; if (text.Length maxLength) text = text.Substring(0, maxLength); text = Regex.Replace(text, s2, ); /two or more spaces text = Regex.Replace(text, ()+|(), n); / text = Regex.Replace(text, (s*&n|Nb|Bs|Sp|P;s*)+, ); / text = Regex.Replace(text, , string.Empty); /any other tags text = text.Replace(, ); return text; #endregion / / 生成随机数 / / private string GenerateCheckCode() #region int number; char code; string checkCode = String.Empty; System.Random random = new Random(); for (int i = 0; i 5; i+) number = random.Next(); if (number % 2 = 0) code = (char)(0 + (char)(number % 10); else code = (char)(A + (char)(number % 26); checkCode += code.ToString(); HttpContext.Current.Response.Cookies.Add(new HttpCookie(CheckCode, checkCode); return checkCode; #endregion / / 生成验证码图片 / public void CreateCheckCodeImage() #region string checkCode = GenerateCheckCode(); if (checkCode = null | checkCode.Trim() = String.Empty) return; System.Drawing.Bitmap image = new System.Drawing.Bitmap(int)Math.Ceiling(checkCode.Length * 12.5), 22); Graphics g = Graphics.FromImage(image); try /生成随机生成器 Random random = new Random(); /清空图片背景色 g.Clear(Color.White); /画图片的背景噪音线 for (int i = 0; i 25; i+) int x1 = random.Next(image.Width); int x2 = random.Next(image.Width); int y1 = random.Next(image.Height); int y2 = random.Next(image.Height); g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2); Font font = new System.Drawing.Font(Arial, 12, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic); System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Blue, Color.DarkRed, 1.2f, true); g.DrawString(checkCode, font, brush, 2, 2); /画图片的前景噪音点 for (int i = 0; i 100; i+) int x = random.Next(image.Width); int y = random.Next(image.Height); image.SetPixel(x, y, Color.FromArgb(random.Next(); /画图片的边框线 g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1); System.IO.MemoryStream ms = new System.IO.MemoryStream(); image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif); HttpContext.Current.Response.ClearContent(); HttpContext.Current.Response.ContentType = image/Gif; HttpContext.Current.Response.BinaryWrite(ms.ToArray(); finally g.Dispose(); image.Dispose(); #endregion / / 获取汉字第一个拼音 / / / static public string getSpells(string input) #region int len = input.Length; string reVal = ; for (int i = 0; i 1) int area = (short)arrCN0; int pos = (short)arrCN1; int code = (area 8) + pos; int areacode = 45217, 45253, 45761, 46318, 46826, 47010, 47297, 47614, 48119, 48119, 49062, 49324, 49896, 50371, 50614, 50622, 50906, 51387, 51446, 52218, 52698, 52698, 52698, 52980, 53689, 54481 ; for (int i = 0; i 26; i+) int max = 55290; if (i != 25) max = areacodei + 1; if (areacodei = code & code max) return Encoding.Default.GetString(new byte (byte)(65 + i) ); return ?; else return cn; #endregion / / 半角转全角 / / / static public string GetQuanJiao(string BJstr) #region char c = BJstr.ToCharArray(); for (int i = 0; i c.Length; i+) byte b = System.Text.Encoding.Unicode.GetBytes(c, i, 1); if (b.Length = 2) if (b1 = 0) b0 = (byte)(b0 - 32); b1 = 255; ci = System.Text.Encoding.Unicode.GetChars(b)0; string strNew = new string(c); return strNew; #endregion / / 全角转半角 / / / static public string GetBanJiao(string QJstr) #region char c = QJstr.ToCharArray(); for (int i = 0; i c.Length; i+) byte b = System.Text.Encoding.Unicode.GetBytes(c, i, 1); if (b.Length = 2) if (b1 = 255) b0 = (byte)(b0 + 32); b1 = 0; ci = System.Text.Encoding.Unicode.GetChars(b)0; string strNew = new string(c); return strNew; #endregion #region 加密的类型 / / 加密的类型 / public enum PasswordType SHA1, MD5 #endregion / / 字符串加密 / / 要加密的字符串 / 要加密的类别 / static public string EncryptPassword(string PasswordString, string PasswordFormat) #region switch (PasswordFormat) case SHA1: passWord = F
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- GA/T 946.2-2025道路交通管理信息采集规范第2部分:机动车登记信息采集和签注
- 幼儿园教师职业倦怠早期预警指标-基于2023年心理健康普查数据建模
- 公司法原理与实务
- 山东省济宁市兖州区2025-2026学年高二下学期期中考试地理试卷
- 煤矿岗位责任制考核标准
- 环保工程监理大纲
- 冷链运输车辆温控数据实时留存溯源管理办法
- 海南琼海市2026年广播电视播音员主持人资格考试(广播电视播音主持业务)复习题库含答案
- 养老机构访客探视时间规范及行为管理办法
- 2026年天津市政府采购代理机构从业人员考试强化复习试题及答案
- 2026年山东省济南槐荫区九年级中考物理二模考试试题(含答案)
- 铁路专用线维护保养方案
- 2026中国移动通信集团海南有限公司第一期社会招聘3人笔试备考试题及答案解析
- 【《自动避障扫地机器人设计》11000字(论文)】
- 2026届江苏省南京市高三二模英语试题(含答案和音频)
- 2026版公司安全生产管理制度及文件汇编
- 解读2025新版职业病分类和目录12大类135种
- 2026形势与政策课件中国风范 大国担当-在世界变局中推动构建新型大国关系
- 2026年中国邮政集团新疆维吾尔自治区分公司招聘笔试参考题库附带答案详解
- 汉俄标题语言的多维对比与解析
- 回转窑基础知识培训课件
评论
0/150
提交评论