Here you can find the source of chopString(String argString, int argLength)
Parameter | Description |
---|---|
argString | a parameter |
argLength | a parameter |
public static String[] chopString(String argString, int argLength)
//package com.java2s; /**//from w ww. jav a2 s . c om * Copyright 2010 Peter Brewer and Daniel Murphy * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { /** * Chops the string into smaller strings with size of * argLength. by daniel * * @param argString * @param argLength * @return */ public static String[] chopString(String argString, int argLength) { if (argString.length() == 0) { return new String[0]; } if (argString.length() <= argLength) { return new String[] { argString }; } String[] ret = new String[(int) Math.ceil(argString.length() / argLength)]; int i; for (i = 0; i < ret.length - 1; i++) { ret[i] = argString.substring(i * argLength, (i + 1) * argLength); } ret[i] = argString.substring(i * argLength); // the last one, so we don't get the // out of bounds exception return ret; } }