473,386 Members | 2,042 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Char reading

I'm trying to read a string from the console like

java TestFile arg1 arg2 .....

and I want then to split arg1 into 'a','r','g','1', to insert into a Stack.

How do I do such conversion ?

response to nu************@yahoo.com

Jul 17 '05 #1
5 8668
import java.lang.*;

public class StringSplitter
{
public static void main(String [] args)
{
byte [] charArr;
charArr=args[0].getBytes;
push(charArr[0]);
}
}

here the array of bytes is single chars .... if args[0] = "karthik"
charArr[0]='k'
charArr[0]='a'
charArr[0]='r'
..
..
..
Nuno Silva <nu************@yahoo.com> wrote in message news:<ne********************@newsfront4.netvisao.p t>...
I'm trying to read a string from the console like

java TestFile arg1 arg2 .....

and I want then to split arg1 into 'a','r','g','1', to insert into a Stack.

How do I do such conversion ?

response to nu************@yahoo.com

Jul 17 '05 #2
import java.lang.*;

public class StringSplitter
{
public static void main(String [] args)
{
byte [] charArr;
charArr=args[0].getBytes;
push(charArr[0]);
}
}

here the array of bytes is single chars .... if args[0] = "karthik"
charArr[0]='k'
charArr[1]='a'
charArr[2]='r'
..
..
..
Nuno Silva <nu************@yahoo.com> wrote in message news:<ne********************@newsfront4.netvisao.p t>...
I'm trying to read a string from the console like

java TestFile arg1 arg2 .....

and I want then to split arg1 into 'a','r','g','1', to insert into a Stack.

How do I do such conversion ?

response to nu************@yahoo.com

Jul 17 '05 #3
Hi Everybody in comp.lang.java!!!
I'm quite new here so please Nuno let me first introduce myself, short...

My name is Piotr (Peter in Eglish), but I'm often using "piotr" in my
signature, to express my growing (not grown yet) experience in the
Computer Science... :-)
I am from Poland and I'm (rather occasional) a reader of this group
since last a few months.
I've been working since 10 years writing software mostly for OS/400
based machines, so my experience is divided into many different
programming techniques and technologies including Java (this one since
about six years).
Last a couple of months I'm also a quite active writer for the "Polish
version" of this group (pl.comp.lang.java) where everyone understanding
our language is welcome also...
I can't make a promise for writing here, but I hope nobody will be
offended with me for my possible future posts here.

Here is also my personal greetings exchanged with all of the reputable
members of this group...

OK, Nuno..., lets back to your problem... I've decided not to answer you
personally because I think You should express a little more precisely
Your questions, and probably most of the people writing here, have no so
much time (I guess...) to talk to you on details of your question, so do
I...
My answer:

Use the following as an example for your TestFile.main method body:

public static void main(String[] args) {
....

Stack stack = ... // instantiate your Stack here

for(int i = 0; i < args.length; ++i) {
String a = args[i]; // (i + 1)th argument

for(int ai = 0; ai < a.length(); ++ai) {
char c = a.charAt(ai); // (ai + 1)th character of a

// now you can add c into your stack...

// assuming your Stack is java.util.Stack...
//...you can do it this way:
stack.push(new Character(c));

}

// and here you can (optionally) do some separation...
//...of your arguments stream :) eg:
if ((i + 1) < args.length)
stack.push(new Character(' '));

}

....
}
Ohh, of course..., you have to consider using StringBuffer or more
"advanced" stack for your particular needs.

Pozdrawiam/Regards
piotr

Nuno Silva wrote:
I'm trying to read a string from the console like

java TestFile arg1 arg2 .....

and I want then to split arg1 into 'a','r','g','1', to insert into a Stack.

How do I do such conversion ?

response to nu************@yahoo.com


Jul 17 '05 #4
Oh... I'm asking everybody to forgive my non-perfect English... this is
not my native language...

I've been working for 10 years..., and probably more "flowers" like
this..., I'm sorry... :-)

Pozdrawiam/Regards
piotr


Piotr Kobzda wrote:
Hi Everybody in comp.lang.java!!!
I'm quite new here so please Nuno let me first introduce myself, short...

My name is Piotr (Peter in Eglish), but I'm often using "piotr" in my
signature, to express my growing (not grown yet) experience in the
Computer Science... :-)
I am from Poland and I'm (rather occasional) a reader of this group
since last a few months.
I've been working since 10 years writing software mostly for OS/400
based machines, so my experience is divided into many different
programming techniques and technologies including Java (this one since
about six years).
Last a couple of months I'm also a quite active writer for the "Polish
version" of this group (pl.comp.lang.java) where everyone understanding
our language is welcome also...
I can't make a promise for writing here, but I hope nobody will be
offended with me for my possible future posts here.

Here is also my personal greetings exchanged with all of the reputable
members of this group...

OK, Nuno..., lets back to your problem... I've decided not to answer you
personally because I think You should express a little more precisely
Your questions, and probably most of the people writing here, have no so
much time (I guess...) to talk to you on details of your question, so do
I...
My answer:

Use the following as an example for your TestFile.main method body:

public static void main(String[] args) {
...

Stack stack = ... // instantiate your Stack here

for(int i = 0; i < args.length; ++i) {
String a = args[i]; // (i + 1)th argument

for(int ai = 0; ai < a.length(); ++ai) {
char c = a.charAt(ai); // (ai + 1)th character of a

// now you can add c into your stack...

// assuming your Stack is java.util.Stack...
//...you can do it this way:
stack.push(new Character(c));

}

// and here you can (optionally) do some separation...
//...of your arguments stream :) eg:
if ((i + 1) < args.length)
stack.push(new Character(' '));

}

...
}
Ohh, of course..., you have to consider using StringBuffer or more
"advanced" stack for your particular needs.

Pozdrawiam/Regards
piotr

Nuno Silva wrote:
I'm trying to read a string from the console like

java TestFile arg1 arg2 .....

and I want then to split arg1 into 'a','r','g','1', to insert into a
Stack.

How do I do such conversion ?

response to nu************@yahoo.com


Jul 17 '05 #5
Hi Everybody in comp.lang.java, again!!!
I'm quite new here so please Nuno let me first introduce myself, short...

My name is Piotr (Peter in Eglish), but I'm often using "piotr" in my
signature, to express my growing (not grown yet) experience in the
Computer Science... :-)
I am from Poland and I'm (rather occasional) a reader of this group
since last a few months.
I've been working for 10 years writing software mostly for OS/400
based machines, so my experience is divided into many different
programming techniques and technologies including Java (this one for
about six years).
Last a couple of months I'm also a quite active writer for the "Polish
version" of this group (pl.comp.lang.java) where everyone understanding
our language is welcome also...
I can't make a promise for writing here, but I hope nobody will be
offended with me for my possible future posts here.

And hope everybody forgive my non-perfect English... this is not my
native language... :)

Here is also my personal greetings exchanged with all of the reputable
members of this group...

OK, Nuno..., lets back to your problem... I've decided not to answer you
personally because I think You should express a little more precisely
Your questions, and probably most of the people writing here, have no so
much time (I guess...) to talk to you on details of your question, so do
I...
My answer:

Use the following as an example for your TestFile.main method body:

public static void main(String[] args) {
....

Stack stack = ... // instantiate your Stack here

for(int i = 0; i < args.length; ++i) {
String a = args[i]; // (i + 1)th argument

for(int ai = 0; ai < a.length(); ++ai) {
char c = a.charAt(ai); // (ai + 1)th character of a

// now you can add c into your stack...

// assuming your Stack is java.util.Stack...
//...you can do it this way:
stack.push(new Character(c));

}

// and here you can (optionally) do some separation...
//...of your arguments stream :) eg:
if ((i + 1) < args.length)
stack.push(new Character(' '));

}

....
}
Ohh, of course..., you have to consider using StringBuffer or more
"advanced" stack for your particular needs.

Pozdrawiam/Regards
piotr

Nuno Silva wrote:
I'm trying to read a string from the console like

java TestFile arg1 arg2 .....

and I want then to split arg1 into 'a','r','g','1', to insert into a Stack.

How do I do such conversion ?

response to nu************@yahoo.com


Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Chris | last post by:
Hi, I'm playing/developing a simple p2p file sharing client for an existing protocol. A 2 second description of the protocol is Message Length = int, 4 bytes Message Code = int, 4 bytes...
20
by: ishmael4 | last post by:
hello everyone! i have a problem with reading from binary file. i was googling and searching, but i just cant understand, why isnt this code working. i could use any help. here's the source code:...
13
by: Matthew Jakeman | last post by:
If i have a pointer, char *. That i have checked is only 1 character long, is just casting it to a char using (char) the best way or is there another way ?
6
by: Sona | last post by:
Hi, What's the advantage/disadvantage of using a "const char*" over a "char*" ? I read some place that char* are string literals that on some machines are stored in a read only memory and cannot...
5
by: Jim Langston | last post by:
In one of my files I am outputting the value of a char into a human readable file. That is, char a = 123; std::ofstream CharFile( ("Players\\" + Name + ".char").c_str()); if ( CharFile.is_open()...
17
by: cnwy | last post by:
Hi, I have a long string in char * and want to convert it to a File * fp. Is there any best way to do it without using tmpfile? Thanks. wy.
4
by: nass | last post by:
hello everyone, i have a bit of problem reading char * strings from a buffer (a shared memory, pointed to by 'file_memory'). basically i have a structure in memory 'ShMem' that can be accessed by...
3
by: coder | last post by:
While reading the page on "Reading C Declarations" <http://www.ericgiguere.com/articles/reading-c-declarations.html> (recommended by Mr. Heathfield at...
7
by: Neo | last post by:
Hi, I have a programs that reads char ouput and should send a signal when it reads "login". I am currently reading into a char array but how do I check for the match? I don't think I can do- char...
12
by: s0suk3 | last post by:
I've seen a lot of functions in the standard library that deal with characters, but a lot them return/take parameters of type int (which is usually the integer that represents the character code in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.