字符串截取
来源:互联网 发布:淘宝村服务站怎样申请 编辑:程序博客网 时间:2024/04/29 10:23
- package cn.youpaoo;
-
- import java.util.ArrayList;
-
-
-
-
-
-
- public class SplitString {
-
- public void splitSt(String str){
-
- String[] strArray = str.split(";");
-
-
- Integer surveyId = Integer.valueOf(strArray[0]);
-
-
- ArrayList strArrayList = new ArrayList();
- for(int i = 1; i < strArray.length; i++){
- strArrayList.add(strArray[i]);
- }
-
- for (int j = 0 ; j < strArrayList.size(); j++){
-
- String tmpParm = (String)strArrayList.get(j);
- String[] subject = tmpParm.split(":");
- String subjectParm = (String)subject[0];
- String[] subjectSplit = subjectParm.split("-");
- String subjectId = (String)subjectSplit[0];
- String subjectType = (String)subjectSplit[1];
-
-
- String optionParm = (String)subject[1];
-
- String[] optionSplit = optionParm.split(",");
- for(int l = 0; l < optionSplit.length; l++){
-
- String optionObj = (String)optionSplit[l];
-
- String[] optionValue = optionObj.split("-");
-
- if(1 == optionValue.length){
- String optionCont = optionValue[0];
- System.out.println("问题的ID为:" + subjectId
- + " 问题的类型为:" + subjectType + "问题的答案为:" + optionCont);
- } else {
- String optionId = optionValue[0];
- String optionSort = optionValue[1];
- System.out.println("问题的ID为:" + subjectId
- + " 问题的类型为:" + subjectType + "问题的选项ID为: " + optionId
- + " 选项的排序为:" + optionSort);
- }
- }
-
- }
- }
-
- public static void main(String[] args){
- SplitString s = new SplitString();
- String str = "5;12-0:10-A;2-1:34-B,天涯;3-0:4-12";
- s.splitSt(str);
- }
-
- }