java - 如果输入有时没有标记,则对数组中的多个字符串进行标记

标签 java android tokenize

我已在此表单中输入内容

<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="95e1f0e6e1d5e1f0e6e1bbf6faf8" rel="noreferrer noopener nofollow">[email protected]</a>

和\或以这种形式

<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b8ccddcbccf8ccddcbcc96dbd7d5" rel="noreferrer noopener nofollow">[email protected]</a>;<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="32465741460072465741461c515d5f" rel="noreferrer noopener nofollow">[email protected]</a>

<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="344051474074405147401a575b59" rel="noreferrer noopener nofollow">[email protected]</a>;<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="64100117105624100117104a070b09" rel="noreferrer noopener nofollow">[email protected]</a>;<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a2d6c7d1d691e2d6c7d1d68cc1cdcf" rel="noreferrer noopener nofollow">[email protected]</a>

我应该在一个字符串数组中标记所有内容,其中每个单元格仅包含一封电子邮件,没有任何分隔符

;

最佳答案

您不想标记化,只需使用split:

String[] emails = { "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="572332242317233224237934383a" rel="noreferrer noopener nofollow">[email protected]</a>;<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="56223325226416223325227835393b" rel="noreferrer noopener nofollow">[email protected]</a>;<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0a7e6f797e394a7e6f797e24696567" rel="noreferrer noopener nofollow">[email protected]</a>", "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="abdfced8dfebdfced8df85c8c4c6" rel="noreferrer noopener nofollow">[email protected]</a>"  };
List<string> result = new ArrayList<String>();

for ( string listOfEmails : emails ) {
  for( string email : listOfEmails.split(";") ) {
    result.Add(email).
  }
}

System.out.println(result);

它适用于所有情况。

关于java - 如果输入有时没有标记,则对数组中的多个字符串进行标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12672458/

相关文章:

java - 我是否应该在 Android 应用程序上将缓冲读取更改为内存中/标记化以读取 100,000 行文件?

c - 在 C 中标记字符串

java - 使用 Java 进行语音采样

java - 如何更改 Eclipse SpringSource 插件使用的 Gradle 版本?

安卓 : LocationManager vs Google Play Services

android - 没有网络连接

regex - 正则表达式/"regular expression"中的正则是什么意思?

java - 在java中合并多个文件

java - 从邮政编码获取纬度/经度

java - 第二次加载时进度条失败