Programming: Write a function that intercept strings, inputs a string and byte, output to a string intercept by byte. But to ensure that the Chinese characters are not taken, such as "I abc" 4, should be "I abc", enter "I am ABC Han DEF", 6, should output "I ABC" instead of "I am ABC Han ". Package string; class splitstring {private string str; private int reference
Public splitstring () {}
Public splitstring (string str, int Bytenum) {this.str = str; this.bytenum = bytenu;
Public void splitit () {
Byte bt [] = str.getbytes (); system.out.println ("length of this string ===>" bt.length); if (ByTenum> 1) {if (BT [ByTenum] <0) { String substrx = new string (bt, 0, - bytenum); system.out.println (Substrx);} else {string substerx = new string (bt, 0, bytenum); system.out.println (Substrex);} } else {if (bytenum == 1) {if (bt [bytenum] <0) {string substr1 = new string (bt, 0, bytenum); system.out.println (SUBSTR1);} else {String Subst2 = new string (bt, 0, bytenum); system.out.println (substr2);}} else {system.out.println ("Input error !!! Please enter the integer of zero:");}}}}
Public class testsplitstring {public static void main (string str = "I am ABC Han DEF"; int Num = 6; splitstring sptstr = new splitstring (str, num); sptstr.splitit ();}}