編寫一個截取字符串的函數,輸入爲一個字符串和字節數,輸出爲按字節截取的字符串。...

package test;

class  SplitString {
 String SplitStr;
 int SplitByte;
 public SplitString(String str,int bytes) {
  SplitStr=str;
  SplitByte=bytes;
  System.out.println("The String is:'"+SplitStr+"';SplitBytes="+SplitByte);
 }  public void SplitIt() {
  int loopCount;
  loopCount=(SplitStr.length()%SplitByte==0)?(SplitStr.length()/SplitByte):(SplitStr.length()/SplitByte+1);
  System.out.println("Will Split into "+loopCount);
  for (int i=1;i<=loopCount ;i++ ) {
   if (i==loopCount){
    System.out.println(SplitStr.substring((i-1)*SplitByte,SplitStr.length()));
   } else {
    System.out.println(SplitStr.substring((i-1)*SplitByte,(i*SplitByte)));
   }
  }
 }  public static void main(String[] args) {
  SplitString ss = new SplitString("test
dddsaf中男大3443n中國43中國人
0ewldfls=103",4);
  ss.SplitIt();
 }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章