私が考えることができる唯一の方法は複雑です 最初に文字列の分割を行うグループの数を取得し、次に各グループの文字数を取得することができます。 あなたがいることを持っている場合は、あなたがグループを作り始めることができ、およびサブグループの1が限度
//creates groups and lengths arrays
string letters = aaa bbbb ccc dd eeeeeee ffffffffff gggggggggggggggg hh iiiiiiiiii;
string[] groups = letters.split(" ");
int[] lengths = new int[groups.length]
for(int i = 0; i<groups.length, i++){
lengths[i] = groups[i].length;
}
int numberofrows;
//starts doing groups: is one element is more that 20, then if 2 elements are more
//than 20, 3 elements more than 20....
// when a sum is more than 20, then the last amount of groups was the one to use
for(int i = 0, i<groups.length<i++){
for(int j = 1, j<=groups.length, j++)
int sum = add(i, j)
if(sum > limit){
numberofrows = j-1;
return;
}
}
}
//this makes the addition of several elements of the array, next to the other
public int add(int index, id sums){
int sum = lengths[index];
for(int i = 0, i<=sums;i++){
sum += lengths[index+i];
}
return sum;
}
固定列サイズまたは無を超えたときに停止しますか? – msarchet
いいえ、列のサイズは任意で、間隔は行内に配置され、折り返しを超えません。行の文字列の量だけが同じでなければなりません。最後の行はlessを持つことができます。 –
行ごとに文字列の制限を教えてください。私はあなたが何を言っているのか理解していると思いますが、最初の行に5文字列があり、次の行に5行の大きな文字列が必要な場合には何を望んでいるのか分かりませんが、 1行あたりの文字列数 "ルール – covertCoder