repalcing / with tabs
This baffles me ....
How do I replace / with tabs using regexp (jdk 14.)
Pattern p = Pattern.compile("/");
String input ="10/26/1980";
Matcher m = p.matcher(input);
String output =null;
if (m.find()){
output = m.replaceAll(args[0]);
}
Please note that replacement should always be read as input not a java literal.
[546 byte] By [
bandaria] at [2007-11-27 10:58:50]

Yours works for me:
Pattern p = Pattern.compile("/");
String input = "10/26/1980";
Matcher m = p.matcher(input);
String output = null;
if (m.find()) {
output = m.replaceAll("\t");
}
System.out.printf("Input : %s , Output : %s%n", input, output);
or, alternately, you could just use the String.replaceAll() method
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#replaceAll(java.lang.String,%20java.lang.String)
String input = "10/26/1980";
String output = input.replaceAll("/", "\t");
System.out.printf("Input : %s , Output : %s%n", input, output);
~Tim
EDIT:
I need to learn to read better! :(
As Emily Latela would say, Nevermind!
SomeoneElse
> To be more specific how should we read string with
> just tab character?
>
> I tried to supply \t as argument but it doesn't read
> as tab.
Yes, thus my EDIT stating that I need to read better. I see nothing that will take a command line arg and let you use it the way you want, but then again, I am probably missing something. I will be watching this thread for an answer myself.
~Tim
Using tab character in the command line is going to be represented as a String.
what I suggest is you read it as string and do a simple compare to check if the string supplied is "\t" if it is so then perform replace with "\t"
No other data type is allowed via command line.
So you have no choice expect to accept as a String and perform a compare.
You can also add a switch for example 1 to insert tab, 2 to insert other character.
I think the first option sound more elegant then the other
Good LucK
Ranjith