Input Command Line Delimiter

All, I have a simple program working that accepts an input file and writes some results to another file based on some findings. I wrote the app so it accepts a delimiter value from the command line. It works well for delimiters like comma, pipe, and space, but I can't figure out how to make it recognize tab. I've tried \t, '\t', "\t", "'\t'"...every variation I can think of. Can anyone shed point me in the right direction?

String test =new String();

String delim =new String();

int i = 1;

InputStream in =new FileInputStream(args[0]);

InputStreamReader converter =new InputStreamReader(in,"UTF8");

BufferedReader r =new BufferedReader(converter);

OutputStream out =new FileOutputStream(args[1]);

Writer w =new BufferedWriter(new OutputStreamWriter(out,"UTF8"));

delim = args[2];

//write header

w.write("Line" + delim +"Character" + delim +"Start" + delim +"End" + delim + r.readLine());

w.write('\r');

w.write('\n');

[1558 byte] By [Chris.Ga] at [2007-11-26 20:31:59]
# 1
try "//t". The first / tells the compiler to look for special characters.Kind regards
DFWeea at 2007-7-10 1:22:02 > top of Java-index,Java Essentials,Java Programming...
# 2

In other words you are asking how you can type a tab character on the command line and have the command shell pass that character to your Java program?

You say you got it to work with space? What did you do for that? Type a space surrounded by quotes? If so, then try typing a tab character surrounded by quotes. (That's the key labelled "Tab" on your keyboard.) It may be that the shell does something with the tab and doesn't pass it to your code, in which case you won't be able to do that.

But this is only a toy application you are writing so I wouldn't worry too much about getting that to work.

DrClapa at 2007-7-10 1:22:02 > top of Java-index,Java Essentials,Java Programming...
# 3
escape sequences use '\t' not '/t'
Bjava at 2007-7-10 1:22:02 > top of Java-index,Java Essentials,Java Programming...
# 4
> try "//t". The first / tells the compiler to look for> special characters.> Kind regardsIt's not the compiler he's talking about, it's the shell he's using to run his program. (Near as I can tell, anyway.)And in any case, it would be \, not /.
jverda at 2007-7-10 1:22:02 > top of Java-index,Java Essentials,Java Programming...
# 5
You could of course have the user type a special sequence, like '/t' (yes forward slash) on the command line and in your code you look for that sequence and convert it to a tab.
jschella at 2007-7-10 1:22:02 > top of Java-index,Java Essentials,Java Programming...
# 6

> You could of course have the user type a special

> sequence, like '/t' (yes forward slash) on the

> command line and in your code you look for that

> sequence and convert it to a tab.

Or, if \t is being taken literally anyway, the \t would be fine as well, although it would probably have to be quoted.

jverda at 2007-7-10 1:22:02 > top of Java-index,Java Essentials,Java Programming...
# 7

For space and other delimiters I wrap it in quotes and it works. The problem with tab is that the Command Prompt window pulls values from the clipboard rather than inserting an actual tab character. I can't find a way with shift, cntl, or alt key combinations either to force it to give me a tab.

It looks like the best bet is to do as suggested and make my delimiter variable equal to char '\t' in code if the argument passed is "tab" or another predetermined value. The problem I'm having now though is how to use the same delimiter variable, 'delim' , in my code as either a string variable or a char primative. Is there a way in code I can change the variable type in a conditional statement that looks for "tab" as a delimiter argument?

Chris.Ga at 2007-7-10 1:22:02 > top of Java-index,Java Essentials,Java Programming...
# 8
Try this:Start your cmd window using:cmd /f:offNow try typing a tab (within either single or double quotes).
doremifasollatidoa at 2007-7-10 1:22:02 > top of Java-index,Java Essentials,Java Programming...
# 9
> cmd /f:offWho you tellin' to F off, buddy?
jverda at 2007-7-10 1:22:03 > top of Java-index,Java Essentials,Java Programming...
# 10

> Try this:

>

> Start your cmd window using:

> cmd /f:off

>

> Now try typing a tab (within either single or double

> quotes).

Thanks. That works. Any insight to my other question? That is, how to use the same delimiter variable in my code set to either a string or char type? Thanks again.

Chris.Ga at 2007-7-10 1:22:03 > top of Java-index,Java Essentials,Java Programming...
# 11

> Thanks. That works. Any insight to my other

> question? That is, how to use the same delimiter

> variable in my code set to either a string or char

> type? Thanks again.

I couldn't make much sense out of that question. You have a string variable. If the string it refers to isn't empty, you can get its first character via the getChar() method. Was that what you had in mind? Changing the type of a variable is a nonsense concept in Java, so suggesting that is just going to lead to blank stares.

DrClapa at 2007-7-10 1:22:03 > top of Java-index,Java Essentials,Java Programming...
# 12

> > Thanks. That works. Any insight to my other

> > question? That is, how to use the same delimiter

> > variable in my code set to either a string or char

> > type? Thanks again.

>

> I couldn't make much sense out of that question. You

> have a string variable. If the string it refers to

> isn't empty, you can get its first character via the

> getChar() method. Was that what you had in mind?

> Changing the type of a variable is a nonsense concept

> in Java, so suggesting that is just going to lead to

> blank stares.

That's helpful to know. I was reading about casting so that's what led to the question. I still don't fully understand the concept. So you are saying that I could use getChar() on my string variable and make my delimiter variable a char type rather than string? Such as: char c = getChar(args[2]) , where args[2] is the delimiter string value passed in the command line?

Chris.Ga at 2007-7-10 1:22:03 > top of Java-index,Java Essentials,Java Programming...
# 13
You would use one variable for the string and a different one for the char, of course. I can't understand where you are going with this idea of one variable for everything so I can't really suggest any more than that.
DrClapa at 2007-7-10 1:22:03 > top of Java-index,Java Essentials,Java Programming...
# 14
> > cmd /f:off> > Who you tellin' to F off, buddy?LOL! It was a serious answer, and it worked for the OP. :-)
doremifasollatidoa at 2007-7-10 1:22:03 > top of Java-index,Java Essentials,Java Programming...
# 15

> You would use one variable for the string and a

> different one for the char, of course. I can't

> understand where you are going with this idea of one

> variable for everything so I can't really suggest any

> more than that.

This is the essence of my question. At the command line, I enter my string variables (args) including the delimiter. If I enter "|", ",", etc. the string gets incorporated into my output via concatenation, as in:

String delim = args[2]

"some text" + delim + "some other text"

Which in the case of the pipe character results in an output of:

some text|some other text

If I want the delimiter value I enter to be the tab character via "\t", how do I still use my delimiter string variable (delim) to concatonate the tab character so that the effect is the same as if I had typed the following in code:

"some text" + '\t' + "some other text"

Resulting in:

some text some other text (I had to simulate a tab with a space. Tab doesn't work in the editor.)

Does that make sense?

Chris.Ga at 2007-7-21 17:57:57 > top of Java-index,Java Essentials,Java Programming...
# 16

>....

> Resulting in:

>

> some text some other text (I had to simulate a tab

> with a space. Tab doesn't work in the editor.)

>

> Does that make sense?

Something like the following.

if ("\\t".equals(args[x])) delim = "\t";

jschella at 2007-7-21 17:57:57 > top of Java-index,Java Essentials,Java Programming...