开发者

Is it possible to ignore Float :: = HexFloat and only see numeric characters?

I'm trying to pa开发者_如何学JAVArse the string value "87306E107" using hasNextDouble. This value is a string and should return false when using hasNextDouble but it returns true. I want know if it's possible to have this method return false? The reason I want to treat this value as a string is because I have to wrap it in single quotes for building a dynamic database insert statement. Here is my code below:

String data = "87306E107,27.1,xyz,123,01449J204";
Scanner scanner = new Scanner(data);
scanner.useDelimiter(",");

if (!scanner.hasNextInt() && !scanner.hasNextDouble()){
    if (DateUtils.isDate(data)){
        //Format date to correct layout
        data = DateUtils.parseStringDate(data, "yyyy-MM-dd", 0);
    }
    //Escape any single quotes
    data = data.replaceAll("'", "''");
    //Wrap in single quotes
    data = "'" + data + "'";
}


You can try a string matcher instead of hasNextDouble():

scanner.hasNext("\\d+(\\.\\d+)?")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜