> Don't forget strings are immutable -- the method
> returns the result:
> > s = s.replace("\t", "");
>
> Again, the simpler replace will suffice when no regex
> patterns are involved.
I did that but it doesn't work.
Works like a charm for me:
public class ReplaceTest {
public static void main(String[] args) {
String s = "1\t2\t3";
s = s.replace("\t","");
System.out.println(s);
}
}
> thats because the doc forgot the 2nd \
>
> hey doc, "dont forget", lol:
> s = s.replace("\\t", "");
>
> (whats up with the teasing today, im outta hand!)
replace() takes ordinary strings, not regular expression strings, so there is
no need to have the double backslash.
> replace() takes ordinary strings, not regular
> expression strings, so there is
> no need to have the double backslash.
yikes. i sat here compiling your code and rubbing my eyes
wondering if i was crazy.
i just kept saying "i know its TWO backslashes".
i think i should call it a day. : /
> > ...
> > Nope. Using 6. But it doesn't want to work for
> some
> > weird reason.
>
> That doesn't say too much: if you'd post the code and
> the exact error message, I'm sure someone (perhaps
> even me) can point out the error in your code.
Doh! I just discovered I had more than one debug session running in NetBeans. I think they may have been part of the problem. I'm going to try it again.
I had already tried
s.replace("\t","");
s.replace("\\t","");
s.replaceAll("\t","");
s.replaceAll("\\t","");
before I posted this question....
> ...
> s.replace("\t","");
> s.replace("\\t","");
> s.replaceAll("\t","");
> s.replaceAll("\\t","");
> ...
1 and 4 will work, 2 and 3 won't.
As already mentioned: both mehods return a new String, so you'll have to do eithers = s.replace("\t","");
ors = s.replaceAll("\\t","");
> > ...
> > s.replace("\t","");
> > s.replace("\\t","");
> > s.replaceAll("\t","");
> > s.replaceAll("\\t","");
> > ...
>
> 1 and 4 will work, 2 and 3 won't.
> As already mentioned: both mehods return a new
> String, so you'll have to do eithers =
> s.replace("\t","");
ors =
> s.replaceAll("\\t","");
Ok. It's working now. Anyone know how I can tell when more than one debug session is running in NetBeans? It's easy in Eclipse. ;-(
> ... Those pre-ANSI C days were the happiest days of
> my life....
All I remember specifically is pre-ANSI C++ and when one compiler author told me that his compiler worked in a way that contradicted "C++ Programming Language" because he didn't agree with the way Stroustrup wanted C++ to work.
It wasn't too surprising to me that Stroustrup's version won.