java编程小问题

[复制链接]
查看11 | 回复4 | 2010-7-22 23:50:57 | 显示全部楼层 |阅读模式
有一个不定长变量如下:
“...and year>=2010 and month>=07 and year>=2010 and month>=07 ”,其中前面的...代表还有其它字符,具体长度不定。我希望得到的结果是:“...and year>=2010 and month>=07 and year=和month>=出现两次,那么就把后面出现的>=换成=2010 and year>=2010 and month>=07 ”,就要得到“...and year>=2010 and year=07 ”.
这个算法想的我头疼,可能解决办法并不复杂,望达人指点迷津,不胜感激!

回复

使用道具 举报

千问 | 2010-7-22 23:50:57 | 显示全部楼层
不理解你为什么要解决这样的问题。大概的代码如下:
String s = "...and year>=2010 and month>=07 and year>=2010 and month>=07 ";
public String convertString(String s) {
StringTokenizer st = new StringTokenizer(s);
int counterYear = 0;
int counterMonth = 0;
String tmpStr = "";
String result = "";
回复

使用道具 举报

千问 | 2010-7-22 23:50:57 | 显示全部楼层
you can use some string process function. i think the question is simple. please use the jdk doc.
回复

使用道具 举报

千问 | 2010-7-22 23:50:57 | 显示全部楼层
用el表达式匹配,返回一个数组。判断它在数组中的下标,如果是偶数说明是第二次出现。
回复

使用道具 举报

千问 | 2010-7-22 23:50:57 | 显示全部楼层
是string类型吗 ? 方法1. 先全替换掉,再把第一个替换回来方法2. 记录第一次出现的位置,把后面的子串替换
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行