C#指定长度分割短信CMPP

public static string[] SplitSMS(string sms, int splitLen)
        {
            int count = (int)Math.Ceiling(sms.Trim().Length / (double)splitLen);
            if (count == 1) return new string[] { sms.Trim() };
            string[] newSMS = new string[count];

            for (int i = 0; i < newSMS.Length; i++)
            {
                if (i < count - 1)
                    newSMS[i] = string.Format("{0}({1}/{2})", sms.Trim().Substring(i * splitLen, splitLen), i + 1, count);
                else
                    newSMS[i] = string.Format("{0}({1}/{2})", sms.Trim().Substring(i * splitLen), i + 1, count);
            }
            return newSMS;
        }

 

你可能感兴趣的:(C#指定长度分割短信CMPP)