English 中文(简体)
分析有问题的解析
原标题:issue with parse
  • 时间:2012-05-23 11:02:03
  •  标签:
  • java
  • android

我有绳子 我需要做自定义解剖器 但我被困在牙套里 我怎么能分析这个...

[TPIN{PrimaryPIN=6152987; IsValidUser=true; }, TPIN{PrimaryPIN=794032; IsValidUser=true; }]

这里有两个字段 :

  1. PrimaryPIN
  2. IsValidUser

我的想法是把它分成数组,但这不是一个好主意,所以你能告诉我,我怎样才能做两个阵列, 来给我提供以下两个阵列的价值: primaryPIN IsvalidUser

最佳回答

s 这里为 primaryPin IsvalidUser 的简单解析器:

    String s = "[TPIN{PrimaryPIN=6152987; IsValidUser=true; }, TPIN{PrimaryPIN=794032; IsValidUser=true; }]";
    Pattern pinPattern = Pattern.compile("PrimaryPIN=([0-9]*);");
    Pattern vuPattern = Pattern.compile("IsValidUser=([^;]*);");
    ArrayList<String> pins = new ArrayList<String>();
    ArrayList<Boolean> validUser = new ArrayList<Boolean>();
    Matcher m = pinPattern.matcher(s);
    while (m.find()) {
        pins.add(m.group(1));
    }
    m = vuPattern.matcher(s);
    while (m.find()) {
        validUser.add("true".equals(m.group(1))?true:false);
    }
问题回答

另一个基于 @Pawe Nadolski s 解决方案的解决方案,

    String s = "[TPIN{PrimaryPIN=6152987; IsValidUser=true; }, TPIN{PrimaryPIN=794032; IsValidUser=true; }]";
    Pattern pinPattern = Pattern.compile("PrimaryPIN=([0-9]*); IsValidUser=(true|false);");
    Map<String, Boolean> pins = new HashMap<String, Boolean>();
    Matcher m = pinPattern.matcher(s);
    while (m.find()) {
        pins.put(m.group(1), new Boolean(m.group(2)));
    }




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签