Resdin first three characters from an input stream

E

El Duderino

Hello all

I'm currently working on a client which needs to compare a server
answer with a local reference string. Does anybody know if there is
a method which can just read in the first three characters of
a string? For example is there something like:

myServerAnswer.beginsWith("XYZ")

Where 'myServerAnswer' contains the data received from the server.

I would know how to code it by creating a an instance of Vector
from java.util.Vector and the using elementAt(postition).
Is there an easier way to accomplish this?
 
C

Chris Smith

El said:
I'm currently working on a client which needs to compare a server
answer with a local reference string. Does anybody know if there is
a method which can just read in the first three characters of
a string? For example is there something like:

myServerAnswer.beginsWith("XYZ")

Where 'myServerAnswer' contains the data received from the server.

Well, if myServerAnswer contains the data received from the server, then
the code you posted will work fine. Perhaps you should be a bit more
specific about how you've stored the data received from the server, what
classes are involved, and so forth.
I would know how to code it by creating a an instance of Vector
from java.util.Vector and the using elementAt(postition).
Is there an easier way to accomplish this?

It depends on where the data is.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
R

Roedy Green

I'm currently working on a client which needs to compare a server
answer with a local reference string. Does anybody know if there is
a method which can just read in the first three characters of
a string? For example is there something like:

how about response.substring( 0, 3);
 
R

Roedy Green

I would know how to code it by creating a an instance of Vector
from java.util.Vector and the using elementAt(postition).
Is there an easier way to accomplish this?

No, that would not be the way to fly, though it could be done if you
were feeling perverse. Vectors store entire strings at each location,
not individual characters.

Study up on the String methods.
 
W

wobegon

El Duderino said:
Hello all

I'm currently working on a client which needs to compare a server
answer with a local reference string. Does anybody know if there is
a method which can just read in the first three characters of
a string? For example is there something like:

myServerAnswer.beginsWith("XYZ")

If myServerAnswer is a String, maybe you're you looking for startsWith
instead of beginsWith?

Sean.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top