The topics are as follows:
The code is as follows:
Package Huawei;import Java.util.arraylist;public Final class demo{/* * function: Write a function, enter as an array of strings, * Iinputlenth each string in the split fraction group by the specified length to output to the new string array. Strings that are not iinputlenth integer multiples are appended with the number 0. * Empty string is not processed, an empty string is encountered to indicate the end of the array, and the function returns. Input: String inputstrarray array pointer * Maximum string number is 50, string length max 255 int iinputlenth specified split length iinputlenth>=1 && <=32 * Return: string array pointer * * Example split input by length 8: ABC 12345789 return: abc00000 12345678 90000000 */public static string[] Convertstringarray (Str Ing[] Inputstrarray, int iinputlenth) {if (iinputlenth >= 1 && iinputlenth <= 32)//split length {arraylist<string > arrayList = new arraylist<string> (); for (int i = 0; i < inputstrarray.length; i++) {String srcstring = InputS Trarray[i];if (srcstring.length () > 0)//NOT NULL {char src[] = Srcstring.tochararray ();//convert string to character array int len = src.length;// Character array length StringBuilder SB = new StringBuilder (); Boolean iscontinue = True;int ring = 1;//is used to empty the count for (int index = 0; iscontinue ; index++, ring++) {if (index = = (len-1))//length and index at the same time {sb.append (Src[index]int tmp_len = Sb.length (); for (; Tmp_len < iinputlenth; tmp_len++) {Sb.append ("0");//Complement 0}arraylist.add (sb.tostring ( )); iscontinue = false;//no longer continues} else{sb.append (Src[index]);//The character array turns into if (ring = = Iinputlenth)//If the length equals the split length, a split is made, Put SB into list and empty SB, next round start {ring = 0;arraylist.add (sb.tostring ()); sb = new StringBuilder ();}}}} if (arraylist.size () > 0) {String data[]=new string[arraylist.size ()];d ata=arraylist.toarray (data);// Turn list to string array return data;}} return null;}}
On-Machine Topic (intermediate)-Re-split the string in the array by the specified length (Java)