Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Remove excessive spaces in string
Message
De
27/07/2009 12:46:49
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Network:
Windows 2008 Server
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01414370
Message ID:
01414790
Vues:
35
>I saw a sample where someone is using aline() to create an array from strings so here is what I came up with:
>
>
>spamstr = alltrim(xfer_payroll.spall)
>ALINES(a__gen5, CHRTRAN(spamstr," ",CHR(13))) && copy the values to array
>If vartype(a__gen5) # 'U' and vartype(a__gen5) # 'L' 
>  first_sw = .t.                   
>  FOR i = 1 TO ALEN(a__gen5,0)
>	IF  !EMPTY(ALLTRIM(a__gen5(i)))
>		IF first_sw = .t.
>			first_sw = .f.
>	 		crtspam = ALLTRIM(a__gen5(i)) && don't put space between string
>		ELSE 
> 			crtspam = crtspam + ' ' + ALLTRIM(a__gen5(i)) && put space while building spam str
> 		ENDIF 
> 	ENDIF 
>  ENDFOR                     
>  RELEASE a__gen5
>  ALINES(a__gen6, CHRTRAN(crtspam," ",CHR(13))) && copy the values to array                    
>                    FOR .f1 = 1 TO ALEN(a__gen6,0)
>                    	g1 = ALLTRIM(a__gen6(.f1))
>                        
>                        Do case
>                            Case g1 == 'FLSA'
>                                cummflsa = evaluate('xfer_payroll.spamt'+allt(str(.f1,3,0)))
>	                            hldflsa = hldflsa + cummflsa
>
>
>the only problem is that the array always seems to be created, even if there is no value in the spamstr. I'm not sure how I can prevent from going into a for loop if the string is empty after testing for "If vartype(a__gen5) # 'U' and vartype(a__gen5) # 'L' ". I was hoping no array is created if the string is empty. However it does and I don't know how to prevent from looping on an empty array. thanks....Nick

I don't think you would want to change out spaces with CHR(13). What if the string contained a carriage return? You also couldn't use EMPTY because that would return .T. for carriage returns

You could do something like
  spamstr = ALLTRIM(xfer_payroll.spall)
  =ALINES(la_lines, spamstr, .t., ' ')
  lc_return = ""
  FOR EACH lc_word IN la_lines
    IF lc_word <> ""
      lc_return = lc_word + " "
    ENDIF
  ENDFOR
  lc_return = TRIM(lc_return)
  RETURN (lc_return)
Don't know if it would be faster or not.
Charles

"The code knows no master." - Chuck Mautz
"Everybody is ignorant, only on different subjects." - Will Rogers
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform