截取制定长度的字符串(经典思路)
2013-08-16
public String getNeedString(String source, int requestLength) { int index = 0; //begin num int sumLength = 0; //sum length String result = ""; while(index < source.length) { char currentChar = source.charAt(index); int currentCharLenth = ("" + currentChar).getBytes().length(); sumlength += currentCharLength; if(sumlength>requestLength) { break; } result += currentChar; index++; } }
每一天都要行动,在前进中寻求卓越。