Hi there -- this is more of a general Java question, but
I'll try to help. You need to employ the StringBuffer's
replace, which will let you replace a substring with
another. String.replace only works on single chars.
Here's the contents of a test app, test.java, that
should help. P.S. I don't guarantee that this is the
most elegant way to do this ... and you could certainly
make a generic replace method that would handle any
substring substitution. I'll leave that part for you
... ;-)
Good Luck!
Bill Graham
-------------------------------------
import java.util.*;
public class test
{
public static void main(String[] args)
{
String str = "This is a \"String\" that I'm
going to work on ...";
StringBuffer sb = new StringBuffer( str );
System.out.println("Original: " + str);
int pos;
while ( (pos = str.indexOf("\"")) > -1 )
{
sb.replace(pos, pos + 1, """);
str = sb.toString();
}
System.out.println("Double Quotes Fixed: " +
str);
while ( (pos = str.indexOf("\'")) > -1 )
{
sb.replace(pos, pos + 1, "'");
str = sb.toString();
}
System.out.println("Single Quotes Fixed: " +
str);
}
}
----------------------------------
Quoting Philipp Chudinov <morpheus@basko.ru>:
> Hi, all!
>
> I've made some kind of primitive "news management
system" with
> jsp&instantDB- just to make myself familiar with Java,
JDBC and InstantDB.
> One of the most stupid problem I've faced with is
replacement of " with
> ". I need to convert " to " because I need
to show data in a
> form - but if there is a " symbol, the form in html
does not render
> properly
> (<input type="blah" value="hereis some value and if
here is also
> some"quotes" this form is not a "valid html
document"">) - also, how is it
> possible to convert ' to smth alse? InstantDB
understands \' fine, but,
> imagine, you should put escape symbol every time you
need to edit a
> story...
>
> When I try to use .replace() method of
java.lang.String, I get an error (I
> am new to java and I can not understand why it
produces an error... In
> vbscript (asp) it is a very simple function
replce(inputstr, what to
> replce,
> what replace with)...)
>
> Maybe, someone can explain me, how things like this
gets processed usually?
>
> P.S. sorry for my poor english.
>
>
-----------------------------------------------------------------------------
> To unsubscribe from this mailing list, send email to
majordomo@enhydra.org
> with the text "unsubscribe instantdb" in the body of
the email.
> If you have other questions regarding this mailing
list, send email to
> the list admin at owner-instantdb@enhydra.org.
>
=========================================
This mail sent through Sinclair's WebMail
http://mail.sinclair.net
-----------------------------------------------------------------------------
To unsubscribe from this mailing list, send email to majordomo@enhydra.org
with the text "unsubscribe instantdb" in the body of the email.
If you have other questions regarding this mailing list, send email to
the list admin at owner-instantdb@enhydra.org.
|