美文网首页
C#字符串截取函数的代码

C#字符串截取函数的代码

作者: xintiantian | 来源:发表于2019-01-11 11:52 被阅读0次

    下面内容段是关于C#字符串截取函数的内容,应该能对小伙伴们有些用途。

    public static string Truncate(this string myString, int limit, string symbol)

    {

        if (myString == null)

            return null;

        if (limit < 0)

            throw new ArgumentOutOfRangeException("limit", limit, "must be 0 or greater");

        if (symbol == null)

            throw new ArgumentNullException("symbol must not be null");

        if (myString.Length < limit)

            return myString;

        return myString.Substring(0, limit) + symbol;

    }

    相关文章

      网友评论

          本文标题:C#字符串截取函数的代码

          本文链接:https://www.haomeiwen.com/subject/gwtxdqtx.html