【发布时间】:2014-04-30 09:58:10
【问题描述】:
我有这个程序部分,它在所有部分都放置了特定的数字。我想要的是让迭代器继续计算单词,即使单词相同。当同一个词再次出现时,这个最近的代码设置了相同的数字。 例如,它应该大致如下所示:
之前-------->>>>之后
AAAA -------->>>> 001 AAAA
血脑屏障--------->>>> 002血脑屏障
中交----->>>>>> 003中交
血脑屏障 ---------->>>>>> 004血脑屏障
我可以用 if 以某种方式解决它吗?比如上面的例子:
int i=0; if (val[1].equals("BBB"){ i++; if(i==2){sections.put("004","BBB"); //only the second B must be changed at all times, that's why I thought when i=2 then section.put(....) stuff can be used.
`
// List of all Sections, [0]=Code, [1]=Expression
我希望我解释清楚。有什么建议吗?
static final ArrayList<String[]> sections= new ArrayList<String[]>();
static final ArrayList section=new ArrayList();
private static String convert (final String s) {
String temp = s;
//replaces the defined section keywords with a unique section code identifier(3 Bits)
final Iterator<String[]> sic = sections.iterator();
while (sic.hasNext()) {
final String[] val = sic.next();
temp = temp.replaceAll("\n(" + val[1] + ")\r?\n--*\r?\n", val[0].length()>0 ? "\n\u25b4\u25ba"+val[0]+"\n$1\n": "\n\n\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
}
return (temp + "\u25b4").replaceAll("\u25ba212(\n" + ratioRam +"\u25b4)","\u25ba222$1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}
// 在另一部分,文件部分被读取。 : 读取列表(节) ;
【问题讨论】:
-
我真的不明白你在做什么。你能更详细地描述你的代码做什么吗?还请解释为什么您当前的代码不能正常工作。
-
CCCC ----------------->>>>>> 003 BBB是正确的还是错字?不应该是003 CCCC吗? -
@Teetrinker,对,我编辑了,谢谢,)
-
我认为,如果您将字符串的频率保留在某些数据结构中而不是作为字符串的一部分,这将更容易和更有效。
-
如果我理解正确,您希望在文档中添加节号(降价?)或类似的东西,其中可能有重复的节名。也许使用
replace而不是replaceAll?