java 字符串多重分组_将字符串分组160个字符并将它们添加到arraylist中

这似乎运作良好 . 我测试了它的消息长度为0,3,160,320,323个字符 . 有更短的写作方式,但我发布这个(一些)清晰度 .

Private Sub SendMessage(message As String)

If message.Length > 0 Then

Dim multiPartMessages As New List(Of String)

'get the number of parts that are 160 characters in length

Dim fullParts As Integer = CInt(message.Length / 160)

'calculate the remaining number of characters

Dim lastPartLength = message.Length - (fullParts * 160)

'if the full message>160 characters in length loop through the string

'in steps of i*160 and add each substring to multiPartMessages

Dim i As Integer

While i < fullParts And fullParts > 0

multiPartMessages.Add(message.Substring(i * 160, 160))

i += 1

End While

'if the last part has more than 0 characters then add them all to multiPartMessages

If lastPartLength > 0 Then

multiPartMessages.Add(message.Substring(fullParts * 160, lastPartLength))

End If

Else

'handle 0 length message here

End If

End Sub

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值