How to get the location of a string in an array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tmt32mj
    New Member
    • Jan 2010
    • 2

    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:
    Code:
    public class BarToZip
    {
    
        // codes for the array with every digit, starting with 0
        private String digits[] = { "||:::", ":::||", "::|:|", "::||:", ":|::|",
    			":|:|:", ":||::", "|:::|", "|::|:", "|:|::" };
        private String barCode;
    
        //constructor
        public BarToZip(String barCode)
        {
            this.barCode = barCode;
        }
    
        public String toZipCode()
        {
            String zipCode = "";
            //starting position of the barcode section to look up
            int beginString = 0;
            //ending position of the barcode section to look up
            int endString = 4;
            
            //looping through the barcode
            for (int i = 0; i < barCode.length(); i++)
            {
                //seperate the barcode into section of 5 symbols
                String toLookUp = barCode.substring(beginString, endString);
                
                //look up the symbol in the array(I might be wrong here)
                for(String s : digits)
                {
                    s = toLookUp;
                }
                
                //return the location of the barcode section(need completion)
                
                
                //add to zip code string(need completion)
                
                //move location of barcode section 5 positions to the right
                beginString = beginString + 5;
                endString = endString + 5;
            }
    
            return zipCode;
        }
    }
    My question is how do I get the value of the string's location in the array? Any help is much appreciated. Thank you.
    Last edited by tlhintoq; Jan 19 '10, 05:55 AM. Reason: [CODE] ... your code here ... [/CODE] tags added
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    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.

    Comment

    • tmt32mj
      New Member
      • Jan 2010
      • 2

      #3
      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.

      Comment

      Working...