zoukankan      html  css  js  c++  java
  • 我的常用代码集

    .Net

    /// <summary>
    /// 获取汉字字符串的首拼音字母字符串
    /// </summary>
    /// <param name="text">需要转换的字符串</param>
    /// <param name="halfChar">半角字符替换符(*不替换)</param>
    /// <param name="fullChar">全角字符替换符(*不替换)</param>
    public static string GetCnSpell(string text, string halfChar = "", string fullChar = "")
    {
        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, 55290 };
    
        string result = "";
        foreach (char item in text)
        {
        byte[] arrCN = System.Text.Encoding.Default.GetBytes(item + "");
        if (arrCN.Length > 1)
        {
            int code = (arrCN[0] << 8) + arrCN[1];
            for (int i = 0; i < 26; i++)
            {
            if (code >= areacode[i] && code < areacode[i + 1])
            {
                result += (char)(i += 65);
            }
            }
            if (code < areacode[0] || code >= areacode[areacode.Length - 1])
            result += fullChar.Replace('*', item); //全角字符替换
        }
        else result += halfChar.Replace('*', item); //半角字符替换
        }
        return result;
    }
    获取汉字字符串的首拼音
    //获取对象Display Name
    Func<object, string, string> getName = (obj, name) =>{
        if (obj.GetType().GetProperty(name) == null) return "null";
        var attr = obj.GetType().GetProperty(name).GetCustomAttributes(typeof(DisplayAttribute), true).FirstOrDefault();
        return (attr != null) ? (attr as DisplayAttribute).Name : "null";
    };
    获取对象Display Name

    JavaScript

    //JS 多行文本格式化
    Function.prototype.getMultiline = function( strFormat ){ 
        var lines = new String(this);
        lines = lines.substring(lines.indexOf("/*") + 4, lines.lastIndexOf("*/"));  
        if(strFormat){
            var strs = lines.split("
    "), lines = "";
            for( i in strs ){
                if(strs[i]) lines += strFormat.replace(/{0}/g,strs[i]);
            }
        }
        window.clipboardData.setData("Text",lines);
        return lines; 
    }   
    var str = function() {  
    /*
    ProductID
    FinanceOrgID
    ProductName
    ProductLimit
    */}.getMultiline('{"{0}",null},
    ');
    多行文本格式化
  • 相关阅读:
    七牛上传图片
    Mysql数据库分布式事务XA详解
    PostgreSQL查询表名称及表结构
    利用DataSet分页方法 小宝马的爸爸
    Flex4中的皮肤(4):使用SkinPart约束Skin 小宝马的爸爸
    Flex4中使用WCF 小宝马的爸爸
    Flex4中的皮肤(3):使用组件数据 小宝马的爸爸
    (转)Flex4中的皮肤(1):自定义SkinnableComponent 小宝马的爸爸
    一起学ASP.NET中如何使用存储过程 小宝马的爸爸
    从宫二的李为看处世哲学 小宝马的爸爸
  • 原文地址:https://www.cnblogs.com/hanf/p/5910187.html
Copyright © 2011-2022 走看看