|
-
April 19th, 2008, 08:12 AM
#1
Searching a String Array
Hi,
At the moment I have a string array setup with:
Code:
ID:2 Avaliablitiy: Available Name:Daveship
What I would like to do is search this array for "Available" and replace it with Unavailable. Does anyone know if this can be done and if so how to do it?
Thanks.
-
April 19th, 2008, 08:40 AM
#2
Re: Searching a String Array
Er, you can loop through the array item by item, and for each item String you can use the String.replaceAll(..) method to replace all instances of 'Available' with 'Unavailable' in the String...
Is that what you wanted?
The biggest difference between time and space is that you can't reuse time...
M. Furst
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
-
April 19th, 2008, 08:48 AM
#3
Re: Searching a String Array
Not really. What ive got to do is have a boat hire company with rowingboats and pedal boats. Ive manged to make constuctors that will create the boats such as:
public RowingBoat(String a, int s, String Name)
Now ignoring pedal boats, my rowingboat array will look like this:
Code:
ID:1 Avaliablitiy: Available Name:Tedship
ID:2 Avaliablitiy: Available Name:Daveship
ID:3 Avaliablitiy: Available Name:Peteship
and what I want to do is be able to change a rowingboat from Available to Unavailable when it is hired out (this will be changed with user input from a menu)
So bassically what its got to do is search the string array for "Available" and replace it with Unavailable. Can this be done?
-
April 19th, 2008, 09:15 AM
#4
Re: Searching a String Array
 Originally Posted by fortune2k
So bassically what its got to do is search the string array for "Available" and replace it with Unavailable. Can this be done?
? That's just what I described in my previous email... can you explain a bit more how what you want to do is different from what I suggested?
But I don't understand why you are storing that information in the array concatenated as a single String. If you have a RowingBoat class, why not use that in the array? When you want to chage a boat from available to unavailable, you only need to call boat.setAvailable(false) (assuming you have such a method), which sets the value of the boolean 'available' flag in Boat. Then if you want to know whether a boat is available, you can call boat.isAvailable(), which returns the value of the boolean 'available' flag in Boat.
It is better to have an approximate answer to the right question than an exact answer to the wrong one...
J. Tukey
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
-
April 19th, 2008, 10:04 AM
#5
Re: Searching a String Array
I think ive done it, thankyou for your help
Last edited by fortune2k; April 19th, 2008 at 10:41 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|