reading tab string

How to input tab to arguments?

publicstaticvoid main(String[] args){

System.out.println("arg 0: " + args[0]);

}

[315 byte] By [bandaria] at [2007-11-27 10:59:31]
# 1

Input tab?

Hippolytea at 2007-7-29 12:23:38 > top of Java-index,Java Essentials,New To Java...
# 2

> Input tab?

I mean how to I supply tab as an argument?

bandaria at 2007-7-29 12:23:38 > top of Java-index,Java Essentials,New To Java...
# 3

> > Input tab?

>

> I mean how to I supply tab as an argument?

java YourProgram tab

Hippolytea at 2007-7-29 12:23:38 > top of Java-index,Java Essentials,New To Java...
# 4

> > Input tab?

>

> I mean how to I supply tab as an argument?

*** Amazing Mind Reading Ability ***

I'll bet you're talking about doing this in your IDE, aren't you? If so, please be specific.

petes1234a at 2007-7-29 12:23:38 > top of Java-index,Java Essentials,New To Java...
# 5

When you type in the command line, your computer's command line interpreter (CLI) is reading the input and passing it to Java as a string variable. Different CLI's do it differently, as this forum thread explains:

http://www.velocityreviews.com/forums/t295909-passing-tab-char-in-command-line.html

If none of the suggestions work for you, consider adopting some convention to represent a tab character in your input, and then in your Java code parse the input array, looking for the substitute input, and convert it to a tab character.

ChuckBinga at 2007-7-29 12:23:38 > top of Java-index,Java Essentials,New To Java...
# 6

> When you type in the command line, your computer's

> command line interpreter (CLI) is reading the input

> and passing it to Java as a string variable.

> Different CLI's do it differently, as this forum

> thread explains:

>

> http://www.velocityreviews.com/forums/t295909-passing-

> tab-char-in-command-line.html

>

> If none of the suggestions work for you, consider

> adopting some convention to represent a tab character

> in your input, and then in your Java code parse the

> input array, looking for the substitute input, and

> convert it to a tab character.

Well actually it is not a command line but web form. I have a form with 3 inputs,

1. search String

2. Replacement String

3. Test String

so there was a case how to replace / with tab in test string. I am not able to capture tab when I enter \t for replacement string and do replaceAll() on test string. I am definitely missing something here.

bandaria at 2007-7-29 12:23:38 > top of Java-index,Java Essentials,New To Java...
# 7

Here's a test program to fiddle with. It works on my Windows XP. However, changing the iff to test for "\t" instead of "/t" does not. Your environment may react differently, as previously noted.

class Z

{

public static void main(String[] args)

{

String testString = "Replace this forward slash / with a tab";

String out = "";

if (args[0].equals("/t"))

{

out = testString.replaceAll("/", "\t");

}

System.out.println(args[0]);

System.out.println(out);

}

}

ChuckBinga at 2007-7-29 12:23:38 > top of Java-index,Java Essentials,New To Java...
# 8

> Here's a test program to fiddle with. It works on my

> Windows XP. However, changing the iff to test for

> "\t" instead of "/t" does not. Your environment may

> react differently, as previously noted.

> class Z

> {

>public static void main(String[] args)

> {

> String testString = "Replace this forward

> slash / with a tab";

> String out = "";

> if (args[0].equals("/t"))

> {

>out = testString.replaceAll("/", "\t");

>}

>System.out.println(args[0]);

>System.out.println(out);

> }

> }

I do know that if I use "\t" in java program it works but how do we suppl that as argument as tab not as "\t" literal to command line?

bandaria at 2007-7-29 12:23:38 > top of Java-index,Java Essentials,New To Java...
# 9

Now it makes sense, I thought you are trying on a application (using command line)

Solution is:

If you use "\t" within double quote it is a string, try '\t' a single quote means a character

Good Luck

Ranjith

ranjith98a at 2007-7-29 12:23:38 > top of Java-index,Java Essentials,New To Java...
# 10

> Now it makes sense, I thought you are trying on a

> application (using command line)

>

> Solution is:

>

> If you use "\t" within double quote it is a string,

> try '\t' a single quote means a character

>

> Good Luck

> Ranjith

You still don't get it. :-) "\t" or '\t' is java literal and it is not part of my code but need to be passed input to the program, may be it is from command line, or web form (and not from java program) :-)

bandaria at 2007-7-29 12:23:38 > top of Java-index,Java Essentials,New To Java...
# 11

> You still don't get it. :-) "\t" or '\t' is java

> literal and it is not part of my code but need to be

> passed input to the program, may be it is from

> command line, or web form (and not from java program)

> :-)

Then it has nothing to do with java and everything to do with either your shell or browser. Getting the browser to accept and transmit the correct data is independent of your java code.

hunter9000a at 2007-7-29 12:23:38 > top of Java-index,Java Essentials,New To Java...
# 12

Anyway I figured out a way for this, at least with web form with text field.

Type a tab in notepad and copy and paste it in text field of HTML form and there it works magically :-)

bandaria at 2007-7-29 12:23:38 > top of Java-index,Java Essentials,New To Java...
# 13

If it did work then its not a tab its just a String with some white spaces :)

Good Luck

Ranjith

ranjith98a at 2007-7-29 12:23:38 > top of Java-index,Java Essentials,New To Java...