Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: dan delpuerto
  
 
 
 dan delpuerto
 To: Nathan Davies
  Where is Nathan Davies?
 Newcastle
 United Kingdom
 Nathan Davies
 Tags
Subject: RE: For Exiting early
Thread ID: 75443 Message ID: 79221 # Views: 1 # Ratings: 0
Version: Visual FoxPro 6 Category: General VFP Topics
Date: Thursday, October 13, 2005 11:56:36 PM         
   


you're welcome !



> I have tried this and it works with out a hitch, this is great.
>
> Thank you very much. I have learnt a few new tricks and am really pleased with this so thanks again.
>
> > Please try this:
> >
> > ? AddSpaces("Mrs.Hillary&DoughNuts&Harbor Duffy& Hello-World ")
> > The result is "Mrs. Hillary & DoughNuts & Harbor Duffy & Hello - World ".
> >
> >
> > func AddSpaces
> >  parameters s
> >  local s2, lSpaced
> >  s2 = ""
> >  lSpaced = .T.
> >  for i = 1 to len(s)
> >      c = subs(s, i, 1)
> >      * you may insert more characters within the "$-"
> >      if !lSpaced .and. (isUpper(c) .or. (c $ "&-"))
> >         s2 = s2 + " "
> >      endif
> >      s2 = s2 + c   
> >      lSpaced = (c==" ")
> >  next i
> >  return s2
> > 

> > *-------
> > Good luck..
> >
> > > I have a function that takes in one string and adds spaces around & and - and before capital letters. It is very simple and should work just fine. However, the for loop in it is exiting early. I have included the code here for you to examine.
> > >
> > > Any help or suggestions on this will be most appreciated
> > >
> > > FUNCTION AddSpaces
> > > PARAMETERS cString
> > > 
> > >   FOR i = 1 TO LEN(cString)
> > >    IF (BETWEEN(ASC(SUBSTR(cString, i, 1)), 65, 90) AND i > 1 AND ;
> > >      ASC(SUBSTR(cString, i-1, 1)) <> 32 ) ;
> > >      OR ((ASC(SUBSTR(cString, i, 1)) = 38 OR ASC(SUBSTR(cString, i, 1)) = 45) AND ASC(SUBSTR(cString, i-1, 1)) <> 32)THEN
> > >     *- this is an upper case letter, not preceeded by a space already or & not preceeded by a space
> > >     cString = STUFF(cString, i, 0, " ")
> > >    ENDIF && end of IF (between(....
> > >   ENDFOR && end of FOR i = 1 TO LEN(cString)
> > >  
> > >  RETURN cString
> > > ENDFUNC
> > > 

> > > When calling this with the string "MrsJingChen" the output is "Mrs Jing Chen", however if it is called with "MrsJingChen&MissHillaryBanks" the output is "Mrs Jing Chen & MissHillaryBanks" So you see the problem.
> > >
> > > I have stepped through the code and can see that for some reason it is exiting the FOR loop early, about 6 iterations early.
> > >
> > > Many thanks
> > >
> > > Nathan Davies

>
>
>
> Nathan Davies


ENTIRE THREAD

For Exiting early Posted by Nathan Davies @ 8/24/2005 5:13:30 AM
RE: For Exiting early Posted by Barbara Peisch @ 8/24/2005 6:58:11 AM
RE: For Exiting early Posted by Nathan Davies @ 8/24/2005 10:37:08 AM
RE: For Exiting early Posted by Boudewijn Lutgerink @ 8/25/2005 11:18:06 AM
RE: For Exiting early Posted by dan delpuerto @ 10/12/2005 3:33:11 PM
RE: For Exiting early Posted by Nathan Davies @ 10/12/2005 6:02:01 PM
RE: For Exiting early Posted by dan delpuerto @ 10/13/2005 11:56:36 PM
RE: For Exiting early Posted by Ken Murphy @ 10/12/2005 4:08:05 PM
RE: For Exiting early Posted by Dennis Longfellow @ 10/12/2005 5:14:19 PM