Re: Beaker: twitter web service project proposal
In case anyone is interested, here's the VB.Net version of the multi-tweet code:
Code:
If Tweet_TextBox.Text.Length > 140 Then
Do While tempTweet.Length >= 132
chunkCut = 132
While tempTweet.Substring(chunkCut, 1) <> " "
'test for punctuation too (?!,;)
chunkCut = chunkCut - 1
End While
tweetChunk(chunkCount) = tempTweet.Substring(0, chunkCut).Trim
tempTweet = tempTweet.Remove(0, chunkCut)
chunkCount = chunkCount + 1
Loop
tweetChunk(chunkCount) = tempTweet.Trim
For tweets = 0 To chunkCount
tweetUpdate = (tweets + 1).ToString & "/" & (chunkCount + 1).ToString & " " & tweetChunk(tweets)
If tweets < chunkCount Then tweetUpdate = tweetUpdate & " +"
tw.Update(tweetUpdate)
Next
Else
tw.Update(Tweet_TextBox.Text)
End If
Tweet_TextBox.Clear()
Basically it looks to see if the tweet has more than 140 characters, and if so, breaks it down into serialized chunks. Because it can't predict the number of chunks accurately, I allow for prefixed serial part to be xx/yy so if it's x/y then the tweet "misses" 3 characters for total length (I add a space too). In addition, I add a space and + character at the end so that's 2 more. In other words, most tweets will be 135 characters or less.
|