[id]5554323[id!][destid]10657302023180404[destid!][srcterminalid]13518841197[srcterminalid!][msgcontent]好的[msgcontent!][receivetime]20090409165217[receivetime!]像上面这样的一个字符串,怎么把数据提取出来,如下面这种格式:
id=5554323;
destid=10657302023180404;
number=13518841197;
mgs=好的;
receivetime=20090409165217;
用什么方法,请高人指点,不胜感谢!

解决方案 »

  1.   

    压栈再出栈,具体也不懂
    参考XML解析的思路看看
      

  2.   

    刚帮你写好的程序:package test;import java.util.HashMap;
    import java.util.Iterator;
    import java.util.Map;
    import java.util.Set;/**
     * @author mingjian.zheng
     */
    public class Test {
    private static Map <String,String> map = new HashMap<String,String>();
    private static int fromIndex = 0;
    private static int toIndex = 0;
    public static void getStr(String str){
    fromIndex = str.indexOf("[", fromIndex);
    toIndex = str.indexOf("]", fromIndex);
    String key = str.substring(fromIndex+1,toIndex);
    fromIndex = toIndex;
    toIndex = str.indexOf("[", fromIndex);
    String value = str.substring(fromIndex+1, toIndex);
    fromIndex = str.indexOf("!]", toIndex);
    map.put(key, value);
    if(fromIndex <= str.indexOf("[", fromIndex)){
    getStr(str);
    }else{
    return;
    }
    }
    public static void main(String[] args) {
    String str = "[id]5554323[id!][destid]10657302023180404[destid!][srcterminalid]13518841197[srcterminalid!][msgcontent]好的[msgcontent!] [receivetime]20090409165217[receivetime!]";
    getStr(str);
    Set<Map.Entry<String,String>> set = map.entrySet();
    Iterator<Map.Entry<String,String>> it = set.iterator();
    while(it.hasNext()){
    Map.Entry<String, String> me = it.next();
    System.out.println(me.getKey()+" : "+me.getValue());
    }
    }
    }
      

  3.   

    运行结果为:
    destid : 10657302023180404
    srcterminalid : 13518841197
    receivetime : 20090409165217
    msgcontent : 好的
    id : 5554323