please help...
Given: String str1= "abc\"def";
String str2= "\"1234\"";
Required: String str1 = "abcdef";
String str2 = "1234";
Thanks in advance..
> please help...
>
[quoted text clipped - 5 lines]
>
> Thanks in advance..
Have a look at String.replaceAll()
<http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#replaceAll(java.la
ng.String,%20java.lang.String)>
Thomas
Roedy Green - 08 Jul 2005 14:53 GMT
><http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#replaceAll(java.la
ng.String,%20java.lang.String)>
that is a fairly heavy duty tool for such a lightweight problem.

Signature
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm
Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
> Given: String str1= "abc\"def";
> String str2= "\"1234\"";
>
> Required: String str1 = "abcdef";
> String str2 = "1234";
You have several implementation options that mainly fall into two
catagories: Code a loop that scans throught the characters of the string
and build up a new string without the quotes, or use regular
expressions. The loop is good if you want to control resources (CPU and
RAM) spend solving the problem, and the regex is good if you just want
to write it simple.
If you use Java 1.5, the regex can be done like:
String str1 = " .... ";
String str1WithoutQuotes = str1.replaceAll("\"","");
In Java 1.4 the same effect can be achieved by
String str1WithoutQuotes =
java.util.regex.Pattern.compile("\"").matcher(str1).replaceAll("");
If you have plenty of those I recommend you put it into a convenience
method somewhere like
private static final java.util.regex.Pattern QUOTE_PATTERN =
Pattern.compile("\"");
public static String removeQuotes(String s) {
return QUOTE_PATTERN.matcher(s).replaceAll("");
}
Regards,

Signature
Filip Larsen
Thomas Kellerer - 08 Jul 2005 11:29 GMT
> You have several implementation options that mainly fall into two
> catagories: Code a loop that scans throught the characters of the string
[quoted text clipped - 12 lines]
> String str1WithoutQuotes =
> java.util.regex.Pattern.compile("\"").matcher(str1).replaceAll("");
String str1WithoutQuotes = str1.replaceAll("\"","");
will work with 1.4 as well.
Thomas
bronby - 11 Jul 2005 10:20 GMT
String str1WithoutQuotes = str1.replaceAll("\"","");
thanks, this is what i need...
thanx evry1
Filip Larsen - 08 Jul 2005 18:36 GMT
> If you use Java 1.5, the regex can be done like:
>
[quoted text clipped - 5 lines]
> String str1WithoutQuotes =
> java.util.regex.Pattern.compile("\"").matcher(str1).replaceAll("");
I dont know why I got the idea that String.replaceAll() first appeared
in 1.5.
String.replaceAll() has of course been there since 1.4.
Regards,

Signature
Filip Larsen
>please help...
>
[quoted text clipped - 3 lines]
>Required: String str1 = "abcdef";
> String str2 = "1234";
I assume you are not complaining about the use of \ and you want to
avoid dealing with that, but that you want to get rid of " in a
string. You get rid of it the same way you would any other character.
It may be easier to follow what I am doing if I want to get rid of all
the Zs. I trust you can deal with converting every Z to \" when you
write the code.
if ( text == null )
{
// nothing to do.
return null;
}
if ( text.indexOf( 'Z' ) < 0 )
{
// nothing to do.
return text;
}
StringBuilder sb = new StringBuilder( text.length );
for ( int i=0; i<text.length(); i++ )
{
char c = text.charAt( i );
if ( c != 'z' )
{
sb.append( c );
}
}
return sb.toString();

Signature
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm
Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes