文本结构化,分隔符有两种

博客讨论了如何处理包含温度、速度、降水和时间信息的.txt文件。当第四项存在时,需要使用冒号作为分隔符将字符串拆分为五列。问题涉及到文本结构化,解决方案建议使用SPL来实现,它能将文件内容转化为结构化的二维表。
摘要由CSDN通过智能技术生成

【问题】

I have a .txt called readings, it has the following data in it:

-10,3NW,15cm,4:38
5,15SW,8mm,2:8
8,8ENE,2mm,:25
-5,0,7cm,1
-3,0,3mm

Where the first position represents the Temperature, speed, precipitation and time(hours and minutes)
I want to split the string with tokens = line.split(":"); only if the fourth token exists. My code for splitting the string without doing any splits with the delimiter : is:

try {
        input = new BufferedReader(new FileReader("readings.txt"));

        line = input.readLine();
        while (line != null ) {
            tokens = line.split(",");

            temperature = Integer.parseInt(tokens[0].trim());

            tokens[1] = tokens[1].trim();
            separation = firstNonNumericPosition(tokens[1]);


            if (separation == 0 || (separation < 0 && Int
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值