reading tab string
How to input tab to arguments?
publicstaticvoid main(String[] args){
System.out.println("arg 0: " + args[0]);
}
How to input tab to arguments?
publicstaticvoid main(String[] args){
System.out.println("arg 0: " + args[0]);
}
> > 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.
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.
> 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.
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);
}
}
> 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?
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
> 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) :-)
> 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.
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 :-)