Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

String length in bytes

807580Aug 22 2010 — edited Aug 23 2010
Description:*
I'm writing an irc bot, using PircBot
The bot can only send String messages of maximum 512 bytes, including an added "\r\n".
Strings longer than this will be truncated before sending.

I want to check if the String is longer than 512b, and cut it up in separate Strings,
using a recursive method:

Pseudo:*
method splitMessage( String message ){


    if message including \r\n is larger than 512 bytes{


        message1 = first part of the message, including \r\n no longer than 512 bytes;

        message2 = rest of the message;


        send message1;

        splitMessage( message2 );

    }

    else{

        send message;

    }

}
My problem:* I don't know how to check the byte length of a String, and how to cut it up in 512b chunks.
Would this be possible in any way? Or do I need a diffent approach?

Thanks in advance,
Tayotoshi
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 20 2010
Added on Aug 22 2010
10 comments
2,532 views