This topic has been archived. It cannot be replied.
-
工作学习 / IT技术讨论 / Java problemI have a String template like
abcd:col1:efghij:col2:klmno:col3:pqrs.....xyz
and I have a resultset get from database.
for ex. col1 col2 col3 col4 col5...
AA BB CC DD EE
FF GG HH II JJ
for each row in resultset,I have to replace the template like this.for ex. the 1st row have:
abcdAAefghijBBklmnoCCpqrs.....xyz
for 2nd row will be:
abcdFFefghijGGklmnoHHpqrs.....xyz
what's the fast way to do this?
thank you
-richwin(今夕何夕);
2004-5-6
{474}
(#1712837@0)
-
if possible, try to change your sql select-statement to combine all fields to one string
-linside(快刀㊣);
2004-5-6
(#1712878@0)
-
Regular Expression. String.Split(), java.util.regex .
-canadiantire(Crappy Tire);
2004-5-6
(#1713021@0)
-
more detail please
Thank you
-richwin(今夕何夕);
2004-5-6
(#1713272@0)
-
是这样的,用字符串替换运行速度要快很多。用RE比较灵活和容易编程。...用RE还有个问题就是你得template,:colx:的个数是否是变化的。如果是变化的,用RE并不方便。如果是固定个Col个数的用pattern="/(\w+)\:col\d\:/" ... 我用过perl,grep,php的RE,Java没有用过,但是没有大的区别,只是Java的Document写得很不清楚,如果你没有用过RE可以找一个教程看一下。Google上很多,看一下,特别是subpattern。Java Document不适和用来学习。看一下这个:
http://www.oursland.net/projects/regexp/
http://www.javaregex.com/tutorial5.html
另外楼上几位兄弟推荐直接SELECT也是好主意。
-canadiantire(Crappy Tire);
2004-5-7
{484}
(#1714312@0)
-
Just give you an idea if you use Oracleselect REPLACE('abcd:col1:efghij',':col1:',col1) "MyString" from (select col1from table_name);
-oxknife(闲人——瞎忙!!!);
2004-5-7
{100}
(#1714183@0)