【问题标题】:how to get specific data from the sentence [closed]如何从句子中获取特定数据[关闭]
【发布时间】:2012-11-01 10:44:07
【问题描述】:
public class newsidlink{
    public static void main (String[] args) throws Exception{

       String msg="ABCD NEWSBULLETIN01 Issued at HHSSIST NT=2147IST 28Oct2012  Name";
       //to do code 
    }
}

您好我是java初学者....请帮助我如何从上面的字符串中获取所需的参数?我对NEWSBULLETIN01 和将 NewsTime NT 转换为 SQL 原生格式感兴趣?

请给我推荐一下?

【问题讨论】:

  • {@Chris}我尝试使用子字符串、拆分方法来获取数据...我有兴趣通过使用正则表达式或模式匹配来获取数据...

标签: java regex scrape


【解决方案1】:

使用substring()。 阅读它here

   String msg="ABCD NEWSBULLETIN01 Issued at HHSSIST NT=2147IST 28Oct2012  Name";
           //to do code 
    System.out.pritnln(msg.subString(5,19));

通过使用 String.split();

String[] arr = msg.split("\\s");

System.out.println(arr[1]);

【讨论】:

  • 这对我来说就像一个黑客。不是一个非常通用的解决方案。
  • @maba string.split("\\s") 是一个黑客??
  • 不,具有固定子字符串索引等的整个解决方案。
  • @chaitanya10:我尝试使用子字符串、拆分方法来获取数据......我有兴趣通过使用正则表达式或模式匹配来获取数据......
  • String.split() 它自己使用正则表达式,\\s 是查找空格的模式
猜你喜欢
  • 1970-01-01
  • 2017-04-11
  • 1970-01-01
  • 1970-01-01
  • 2014-10-25
  • 1970-01-01
  • 2016-05-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多