473,698 Members | 2,522 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Array with text as index?


I am working on a program that accepts data from a web form like this:

Parm Value
Doug Doug
Doug_age 40
Doug_phone 111-222-3333

Kelly Kelly
Kelly_age 42
Kelly_phone 222-333-4444

Basically I get the persons name then an _ and then the parm name. If
I don't get the _ I know that it is the name.

There is more data like address, email, ect.... I would like to store
this data in an array and then eventually insert it into a dataabse.
What I want to do is build an array that holds this data, but has an
"index" by name.

For example:

MyData[Doug][age] = 40;
MyData[Doug][phone] = 111-222-3333;

MyData[Kelly][age] = 42;
MyData[Kelly][phone] = 222-333-4444;
Anyone have an idea how I would go about this?

Thanks,
Doug

Jul 18 '05 #1
2 2574
do*****@kc.rr.c om wrote:
I am working on a program that accepts data from a web form like this:

Parm Value
Doug Doug
Doug_age 40
Doug_phone 111-222-3333

Kelly Kelly
Kelly_age 42
Kelly_phone 222-333-4444

Basically I get the persons name then an _ and then the parm name. If
I don't get the _ I know that it is the name.

There is more data like address, email, ect.... I would like to store
this data in an array and then eventually insert it into a dataabse.
What I want to do is build an array that holds this data, but has an
"index" by name.

For example:

MyData[Doug][age] = 40;
MyData[Doug][phone] = 111-222-3333;

MyData[Kelly][age] = 42;
MyData[Kelly][phone] = 222-333-4444;
Anyone have an idea how I would go about this?


Take a look at java.util.Map and its implementations .

HTH,
Ray

--
XML is the programmer's duct tape.
Jul 18 '05 #2
do*****@kc.rr.c om skrev:
I am working on a program that accepts data from a web form like this:

Parm Value
Doug Doug
Doug_age 40
Doug_phone 111-222-3333

Kelly Kelly
Kelly_age 42
Kelly_phone 222-333-4444

Basically I get the persons name then an _ and then the parm name. If
I don't get the _ I know that it is the name.

There is more data like address, email, ect.... I would like to store
this data in an array and then eventually insert it into a dataabse.
What I want to do is build an array that holds this data, but has an
"index" by name.

For example:

MyData[Doug][age] = 40;
MyData[Doug][phone] = 111-222-3333;

MyData[Kelly][age] = 42;
MyData[Kelly][phone] = 222-333-4444;
Anyone have an idea how I would go about this?

Thanks,
Doug


Write a class for holding a person's data and store the person-objects
in a HashMap with the name as key (- is the first name really always
unique in your app?). (Use a LinkedHashMap if you want order preserved.)
If you really, really want an array, you could of course map names to
indices (in a HashMap). The get-operation is placed in a method like
getIndx(), and this is called where an index is needed:
MyData[getIndx(Doug)][age]. /ulf
Jul 18 '05 #3

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

Similar topics

3
15509
by: Roy Riddex | last post by:
I've just moved onto 2-D Arrays in my VB6 beginners book. I'm struggling to get my head around the following problem but no doubt you will think it rather easy. My program is supposed to allow up to 20 students to enter their name and 3 exam marks, with each students details being entered into a 2-D Array upon the click of a command button. There is also a list box and another command button which will display the contents of the array. I...
13
1594
by: Martin Altschwager | last post by:
Hi, I desperately need some help with what I assume to be a minor problem that I just can't solve. I'm writing a page where on mouseover a link, an image needs to be displayed and some text, which is defined inside an array, sould appear inside a table cell (whose id is "tdDesc"). That's basically what's in the HTML-file:
35
6643
by: VK | last post by:
Whatever you wanted to know about it but always were affraid to ask. <http://www.geocities.com/schools_ring/ArrayAndHash.html>
38
5212
by: VK | last post by:
Hello, In my object I have getDirectory() method which returns 2-dimentional array (or an imitation of 2-dimentional array using two JavaScript objects with auto-handled length property - please let's us do not go into an "each dot over i" clarification discussion now - however you want to call - you call it ;-) array contains records of all files in the current dir. array contains records of all subs in the current dir
11
39462
by: deko | last post by:
I need to create a basic one-dimensional array of strings, but I don't know how many strings I'm going to have until the code is finished looping. pseudo code: Dim astrMyArray() Do While Not rst.EOF i = i + 1 If rst!Something = Then astrMyArray(i) = rst!Something
1
2482
by: Pradeep Kumar | last post by:
I have a scenario where I am writing a property(using get and set) have to return a member of an object stored in an array of objects! The class user has to pass an index based on which a object i's member is returned from the array. How will the property be declared in C#?
2
6858
by: melanieab | last post by:
Hi, I'm trying to store all of my data into one file (there're about 140 things to keep track of). I have no problem reading a specific string from the array file, but I wasn't sure how to replace just one item. I know I can get the entire array, then save the whole thing (with a for loop and if statements so that the changed data will be saved), but it seems like a lot of unnecessary reading and writing. Is there a way to directly save...
7
1550
by: Peter | last post by:
I want to create a multidemensional arraylist. Seeing as they don't exist I was wondering if there is a way to create a class that works like one. I basically want to use it like this Dim MyArray as classNewArray MyArray.add("Data1", "Data2") or the looping claus....
3
9665
by: Ben | last post by:
Hi I am creating a dynamic function to return a two dimensional array from a delimeted string. The delimited string is like: field1...field2...field3... field1...field2...field3... field1...field2...field3...
6
2723
by: sgottenyc | last post by:
Hello, If you could assist me with the following situation, I would be very grateful. I have a table of data retrieved from database displayed on screen. To each row of data, I have added action buttons, such as "Edit", "Add", and "Comment". Since I do not know how many rows of data will be retrieved - and therefore how many buttons I need - I am using button arrays for each button, like so: echo "<input type=\"submit\"...
0
8676
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8608
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9164
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8870
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3051
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2006
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.