static public String[] split(String text, String token) { int tempPos = 0; int partsCount = 0; do { partsCount++; tempPos++; tempPos = text.indexOf(token, tempPos); } while (tempPos != -1); String[] data = new String[partsCount]; int startPos = 0; int endPos = 0; int partsIdx = 0; while (partsIdx < partsCount) { endPos = text.indexOf(token, startPos); if (endPos == -1)//not found { data[partsIdx] = text.substring(startPos); } else//found { data[partsIdx] = text.substring(startPos, endPos); } startPos = endPos + token.length(); partsIdx++; } return data; }
App Programming/JAVA2008. 4. 7. 17:53