Thursday, September 09, 2010  | 
 
Login
 


Forgot Password ?
     
 
List
 
     

Host for the Toronto Ontario FoxPro User's Group

Fox Ridge Software Inc. - The best in custom business software.

Mike Yearwood awarded Microsoft MVP Visual Foxpro 2008 and again for 2009!

https://mvp.support.microsoft.com/profile/Yearwood

 

 
Drop Last Character
 
Location: BlogsFoxPro / Visual FoxPro tips, tricks and traps.    
Posted by: myearwood 12/19/2005

*

*  DropLastChar.PRG

*  RETURNs the passed string minus the

*  very last character.

*

*  Mike Yearwood's FoxPro Advisor Magazine tip

*  http://my.advisor.com/articles.nsf/aid/14710

*  showed when building a comma-delimited list, the

*  fastest way of dealing with an extraneous comma

*  is to add the comma after each item and then drop

*  the final comma. This routine unconditionally

*  drops the last character from the end

*  of the passed specified string.

*  Further, instead of having a cryptic formula to drop the

*  last character, which you should comment every time it's used,

*  you have a readable function name. This makes the calling

*  code self-documenting.

*

*  It will produce ERROR 11 if parameters are

*  passed improperly.

*

*  Copyright (c) 2005 Fox Ridge Software, Inc. All Rights Reserved

*                120 Parsell Square

*                Toronto, ON M1B 2A6

*                416-282-3942

*                http://www.foxridgesoftware.com

*

*  Donated freely to the Visual FoxPro community.

*

*  Author:  Mike Yearwood - In memory of Drew Speedie

*

*  USAGE

*  =====================================

*  LOCAL m.lcString, m.lnI

*  m.lcString = ""

*  FOR m.lnI = 1 to FCOUNT()

*    m.lcString = m.lcString + FIELD(m.lnI) + ","

*  ENDFOR

*  m.lcString = DropLastChar(m.lcString)

*

*  PARAMETERS

*  =====================================

*  tcString (R) String from which last character

*               must be removed.

*

LPARAMETERS m.tcString

IF VARTYPE(m.tcString) # "C"

  ERROR 11

ENDIF

RETURN IIF(LENC(m.tcString)=0,m.tcString,;

  LEFTC(m.tcString,LENC(m.tcString)-1))

 

Copyright ©2005 Fox Ridge Software
Permalink |  Trackback
     
Copyright 2005-2009 by Fox Ridge Software, Inc. Privacy StatementTerms Of Use