Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

replacing /n with <B >in jdk1.3

  Asked By: Charlie    Date: Jul 31    Category: Java    Views: 925
  

Does anyonw know the best way to replace chars in jdk 1.3?

JDK 1.3 does not support the replaceall() fuunction and and not
exactly sure how do do it.

I do not have the option to upgrade jdk's

Someone mentioned Using .indexOf() and loop writing a script to
reconstruct the string with the replaced values.
Is that the best way?

Share: 

 

6 Answers Found

 
Answer #1    Answered By: Shobhana R.     Answered On: Jul 31

I think it may be the best way.But how about split(String str)? I think it could
be better a little.

 
Answer #2    Answered By: Carl Woods     Answered On: Jul 31

I think you mean <BR> but WTH

String killThoseLinefeeds(String str)
StringBuffer buf = new StringBuffer();
for(int i=0; i< str.size(); i++)
{
char ch = str.charAt(i);
if(ch=='\n')
buf.append("<B>");
else
buf.append("<B>");
}
return buf.toString();
}
or StringTokenizer tok = new StringTokenizer(str, "\n");
while(tok.hasMoreTokens())
buf.append(tok.nextToken();

or a million other really easy bits of code....

 
Answer #3    Answered By: Adal Fischer     Answered On: Jul 31

Actually that last one should be:

StringTokenizer tok = new StringTokenizer(str, "\n");
while(tok.hasMoreTokens())
buf.append(tok.nextToken().append)"<BR>");

 
Answer #4    Answered By: Devlan Jones     Answered On: Jul 31

you right I did know how it should have been
done just did not have the time to think until this weekend and after
sitting down for a few minutes realized that I am a little slow...

 
Answer #5    Answered By: Heru Chalthoum     Answered On: Jul 31

but should not have been

StringTokenizer tok = new StringTokenizer
(question, "\n");
while(tok.hasMoreTokens())
buf.append((String) tok.nextToken()+"<BR>");


Instead of
buf.append(tok.nextToken().append)"<BR>");

 
Answer #6    Answered By: Murad Bashara     Answered On: Jul 31

nextToken() returns a string  - so doesn't need recasting.
the overloaded '+' string operator creates another intermediate
StringBuffer object.
not really an issue for a beginner, but more efficient not to use it too
much.
but I did mean to type:

buf.append(tok.nextToken()).append("<BR>");

 
Didn't find what you were looking for? Find more on replacing /n with <B >in jdk1.3 Or get search suggestion and latest updates.




Tagged: