将传递类别字符串;如何将类别与存储在Hashtable键中的类别进行比较并替换为值?
例如,如果分类来自"整个类别和完整分辨率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中。
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");
答案 0 :(得分:0)
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());
请记住将其标记为答案