Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2005

Tip: Looking for answers? Try searching our database.

newbie help needed with looping.

Thread view: 
Trevnal - 24 Apr 2005 19:57 GMT
Hi,
I was hoping some one may be able to help me. I am trying to get a piece of
code to work, which I thought I had right. But as far as I can tell, it does
not do anything when I run it in jBuilder.
I want to make sure the string that is collected from Keyboard.getString is
a upper case letter and the total length of the string is 8 characters long.

int len;
boalean validName = true;

aa = Keyboard.getString();
     while (!aa.equals("ZZZ"))
     {
        do
        {
            len = partNumber.length();
           {
                if  (!len == 8)
               {
                     validName = false
                }
           }
       }
         while (validName = false)

        do
       {
           for (int index = 0; index <2; index ++)
          {
               if (aa.substring(index,index+1) <"A" \\
(aa.substring(index,index+1) >"Z")
              {
                  validName = false;
              }
         }
     }
     while (validName = false)

    do
   {
        for (int index = 1; index <3; index ++)
      {
            if (aa.substring(index,index+1) <"0" \\
(aa.substring(index,index+1) >"100")
           {
                 validName = false;
           }
     }
 }
 while (validName = false)

            partIn[index] = new Part();
            partIn[index].setPartNumber(partNumber);
}

rest of code.

thanks
Hobbit
Mark Haase - 24 Apr 2005 22:00 GMT
> Hi,
> I was hoping some one may be able to help me. I am trying to get a piece of
> code to work, which I thought I had right. But as far as I can tell, it does
> not do anything when I run it in jBuilder.
> I want to make sure the string that is collected from Keyboard.getString is
> a upper case letter and the total length of the string is 8 characters long.

A better way to do this would be to use a Regex (regular expression).
String has a method

public boolean matches(String regex);

that would do the job. Use could use it as follows:

aa == Keyboard.getString();
validName = aa.matches("[A-Z]{8}") && (aa.length==8);

This would match a string that has 8 consecutive capitalized characters,
I think. The second half of the boolean expression ensures that the
string only has those 8 characters, since a regex will match any
substring as well.

|\/|  /|  |2  |<
mehaase(at)sas(dot)upenn(dot)edu
Jim Gibson - 24 May 2005 20:04 GMT
> aa == Keyboard.getString();
> validName = aa.matches("[A-Z]{8}") && (aa.length==8);
[quoted text clipped - 3 lines]
> string only has those 8 characters, since a regex will match any
> substring as well.

You can also anchor the substring to the beginning and end of the line
with '^' and '$', respectively:

  validName = aa.matches("^[A-Z]{8}$");


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.