用Java解析字符串

穆萨

我有以下格式的字符串

// JCSDL_MASTER b04591342ee71a2baa468d9d2a340ec8 AND
// JCSDL_VERSION 1.0
// JCSDL_START 0980a5f2ef935c4ed153bf975879eac0 twitter.text,contains_any,27-52
twitter.text contains_any "obama, santorum, gingrich, romney, ronpaul, ron paul"
// JCSDL_END
AND
// JCSDL_START f7c18a6fedd90c6b4d77acc14a3a8e5c interaction.type,in,21-29
interaction.type in "twitter,facebook,digg,youtube"
// JCSDL_END
// JCSDL_MASTER_END

我想它的末尾包括换行符,我只需要获取那些不是由//开始的行,//如何仅获取那些行?

路加

很简单,只需将字符串分成几行(注意:\n是换行符的转义字符),然后仅在每行不以//

String[] lines = string.split("\\n");

for (String line : lines)
{
  if (!line.startsWith("//"))
  {
    //use the line and do your thing
  }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章