zoukankan      html  css  js  c++  java
  • asp.net 自定义截取字符串方法

    ///

    /// 截取字符串,不限制字符串长度

    ///

    /// 待截取的字符串  

    /// 每行的长度,多于这个长度自动换行  

    ///

    public string CutStr(string str, int len)

    {

    string s = "";

    for (int i = 0; i < str.Length; i++)

    {

    int r = i % len; int last = (str.Length / len) * len; if (i != 0 && i <= last)

    {

    if (r == 0) { s += str.Substring(i - len, len) + "
    "; } }

    else if (i > last)

    { s += str.Substring(i - 1);

    break;

    } } return s;

    }

     ///

    /// 截取字符串并限制字符串长度,多于给定的长度+。。。

    ///

    /// 待截取的字符串

     /// 每行的长度,多于这个长度自动换行  

    /// 输出字符串最大的长度  

    ///

    public string CutStr(string str, int len, int max)

    { string s = ""; string sheng = "";

    if (str.Length > max)

     {

    str = str.Substring(0, max);

    sheng = "";

    }

    for (int i = 0; i < str.Length; i++)

    { int r = i % len; int last = (str.Length / len) * len; if (i != 0 && i <= last) { if (r == 0) { s += str.Substring(i - len, len) + "";

    }

    }

    else if (i > last)

    {

    s += str.Substring(i - 1); break;

     }

    }

    return s + sheng;

    }

  • 相关阅读:
    JavaScript 操作 Cookie
    Java监控文件夹变化
    Cookie与Session的区别
    常用插件
    Plugin 'org.springframework.boot:springbootmavenplugin:' not found
    mysql安装(windows)
    idea 安装社区版
    linux安装tomcat
    将克隆的项目上传到自己的github
    tomcat安装配置
  • 原文地址:https://www.cnblogs.com/kdkler/p/2047309.html
Copyright © 2011-2022 走看看