• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

restart a loop with labelled break

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is a scaled down version of what i am trying to accomplish.

What i am trying to do is loop through the sTotalAddress, and compare it to the strings in the myString array. When any of the options in the array are located in the string, take the remaining substring of the sTotalAddress and loop through the myString array again, from the beginning of the array (not continue).
Cant seem to get this to work as i seem to have gotten the labelled break wrong. Appreciate any help.
Thanks

[ July 19, 2004: Message edited by: Adrian ]
[ July 19, 2004: Message edited by: Adrian ]
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you give some example data?

It's very unclear, what you like to do.
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Adrian,

Welcome to JavaRanch!

We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.

Thanks Pardner! Hope to see you 'round the Ranch!
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This sounds like it would be a good recursive method.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[aircode]

 
Adrian Airloy
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok here it is with some info in the vars.

int index = 0;
int count = 0;
sTotalAddress = "aarraa bbr.r.bb rr ccrrcc";
String myString[] = new {"r.r." , "rr" , "r r"};
loopAgain:
for (int i = 0; i<myString.length; i++)//loop thru array
{
index = sTotalAddress.indexOf(myString[i]);//compare string in array with total string
if ((index > 0)//if string in array exists in total string..
{
count++;//..then increase count
sTotalAddress = sTotalAddress.substring(index + (myString[i].length()));//extract REMAINDER of total string
break loopAgain;//loop thru new total string and compare to array again
}
}


The question is: how many times the strings in the myString[] are in the string sTotalAddress?

If anyone know a better way of doing this, please let me know. Thanks
Note: what i havent mentioned above is that if an EXACT match is found (where the string in the array can be matched to part of the total string with a space on either side), the loop must be terminated.
[ July 20, 2004: Message edited by: Adrian Airloy ]
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this, but I don't follow the 'exact match'/terminate part.

 
I don't even know how to spell CIA. But this tiny ad does:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic