繁体   English   中英

如何使用AND和OR条件标记特定字符串

[英]how to tokenize the particular string with AND and OR conditions

从JSP下面的类别字符串将通过;如何将类别与存储在哈希表键中的类别进行比较并替换为值?

例如,如果“类别”为“整个类别AND完整PDF PDF(打印)”,则最终输出应为“ 900014 AND 724242”

如果另一个类别作为“(复合图案和封面)或(全尺寸PDF(打印)和封面)”出现,则最终输出应为“(36363636和7697979)或(724242和7697979)”

1.Entire Category AND Full-Res PDF PDF (print)
2.Cover Image OR (Full-Res PDF (print) AND Entire Category)
3.Composite Pattern OR Full-Res PDF (print)
4.(Composite Pattern AND Cover) OR (Full-Res PDF (print) AND Cover)

类别和值将存储在哈希表中。

hashtable.put("Entire Category","900014");
hashtable.put("Full-Res PDF PDF (print)","724242");
hashtable.put("Composite Pattern","36363636");
hashtable.put("Entire Category","352525");
hashtable.put("Cover Image","95757");
hashtable.put("Cover","7697979");
Map<String,String> hashtable = new Hashtable<>();
hashtable.put("Entire Category","900014");
hashtable.put("Full-Res PDF PDF (print)","724242");
hashtable.put("Composite Pattern","36363636");
hashtable.put("Entire Category","352525");
hashtable.put("Cover Image","95757");
hashtable.put("Cover","7697979");

String s = "Entire Category AND Full-Res PDF PDF (print)";

foreach(Map.Entry<String, String> m : hashtable.entrySet())
    while(s.contains(string.getKey()))
            s= s.replace(string.getKey(), string.getValue());

请记住标记为答案

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM