473,398 Members | 2,343 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,398 software developers and data experts.

How to get the location of a string in an array

I'm stuck with an assigment and hope somebody could help. The problem is to write a program to convert a 25 digits code to a 5 digit string represent their location in the array. This is what I have so far:
Expand|Select|Wrap|Line Numbers
  1. public class BarToZip
  2. {
  3.  
  4.     // codes for the array with every digit, starting with 0
  5.     private String digits[] = { "||:::", ":::||", "::|:|", "::||:", ":|::|",
  6.             ":|:|:", ":||::", "|:::|", "|::|:", "|:|::" };
  7.     private String barCode;
  8.  
  9.     //constructor
  10.     public BarToZip(String barCode)
  11.     {
  12.         this.barCode = barCode;
  13.     }
  14.  
  15.     public String toZipCode()
  16.     {
  17.         String zipCode = "";
  18.         //starting position of the barcode section to look up
  19.         int beginString = 0;
  20.         //ending position of the barcode section to look up
  21.         int endString = 4;
  22.  
  23.         //looping through the barcode
  24.         for (int i = 0; i < barCode.length(); i++)
  25.         {
  26.             //seperate the barcode into section of 5 symbols
  27.             String toLookUp = barCode.substring(beginString, endString);
  28.  
  29.             //look up the symbol in the array(I might be wrong here)
  30.             for(String s : digits)
  31.             {
  32.                 s = toLookUp;
  33.             }
  34.  
  35.             //return the location of the barcode section(need completion)
  36.  
  37.  
  38.             //add to zip code string(need completion)
  39.  
  40.             //move location of barcode section 5 positions to the right
  41.             beginString = beginString + 5;
  42.             endString = endString + 5;
  43.         }
  44.  
  45.         return zipCode;
  46.     }
  47. }
My question is how do I get the value of the string's location in the array? Any help is much appreciated. Thank you.
Jan 19 '10 #1
2 1999
tlhintoq
3,525 Expert 2GB
Seeing is this is a school assignment we can't really help you.
We don't know what you have and have not covered in class... what you are and are not allowed to use... etc.
More importantly, giving students the answers is really just cheating and in the long run it short changes your education.
Jan 19 '10 #2
My apologies. I was trying to do my school work and got stuck, figured I'd ask. Didn't know I asked in the wrong forum. Please delete the post. Thank you.
Jan 19 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Dave Smithz | last post by:
Hi there, I have a php script that does some form input validation. As it verifies each field if the field has incorrect data, it appends an error message to an $error array. E.g. if...
26
by: Nige | last post by:
I'm a complete novice to JS. I want to insert the date and time into a document in the format: WB-MMDDHHmm Where: WB- is a fixed string prefix (the whole string is a reference number) MM...
8
by: Gactimus | last post by:
I made the program below. It outputs the smallest number in the array. What I would like to know is how do I output the array location. I am at a loss. For example, since the smallest number in...
5
by: spam_me_ not | last post by:
I already understand that one cannot disable a browser's forward and back functions. This is a situation where I have code working in Mozilla V1.6 and would like something similar for Opera and...
8
by: Phil Powell | last post by:
if (document.location.href.indexOf('?') >= 0) document.location.href = document.location.href.substring(0, document.location.href.indexOf('?')); if (document.location.href.indexOf('#') >= 0) {...
2
by: Brvsra | last post by:
Javascript Experts, I know very little about javascript and could use someone's help. I have created a function to send an email, listed below is the function. The function works fine, with...
11
by: William Buch | last post by:
I have a strange problem. The code isn't written by me, but uses the qsort function in stdlib. ALWAYS, the fourth time through, the memory location of variable list (i.e. mem location = 41813698)...
2
by: Ladbroke | last post by:
Hiya, got a little prob with the syntax for header ( ' Location .... with variable). Usually examples are given with a complete URL, like: ..... header( 'Location: login/testsite/start.php'...
9
by: Slain | last post by:
I have more of a conceptual question now. Let us say I do this:- char *str; --create an array of pointers str= "John"; I thought this would automatically put John at some memory space and...
6
by: Marcolino | last post by:
Hi all, I have a simple problem but I don't know which is the best way to solve it. I need to savo into a table into access DB the location and the size of a form. Is there a way to save...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.