Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Path String Format
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00111405
Message ID:
00111446
Views:
13
>I want to know if somebody know where i can found a function that reduce the display of string to a specific lenght.
>
>Ex. c:\program files\devstudio\vfp\samples.dbf
>
>Function =c:\program files\.\samples.dbf
>lenght=30 spaces
in the following example "c:\program files\devStudio\vfp\samples.dbf" is passed as a parm.


function myStr
lparameters lcFile
local lcMyStr, lcMyStr2, llOk

if pcount() == 1 .and. type('lcFile') = 'C'
llOk = .T.

else
* error message here
return ''
endif


lcFile = alltrim(lcFile)

lcMyStr = ''

* are there more than 2 '\' in the string?
if at('\', lcFile, 3) > 0 && there is more than two.
*-- there is so get str to the 2nd '\'

lcMyStr = left(lcFile, at('\', lcFile,2 )+ "."
*-- returns "c:\program files\"

*-- add the right side of the string
lcMyStr2 = substr(lcFile, rat('\', lcFile))
*-- returns "\samples.dbf"

*-- put them together
lcMyStr = lcMyStr + lcMyStr2
*-- results = "c:\program files\..\samples.dbf"

else
lcMyStr = alltrim(lcFile)
endif

return (lcMyStr)

You could shorten the len of the code but it would make it harder to read.

lcFile = alltrim(lcFile)
return (left(lcFile, at('\', lcFile,2) + '.' + substr(lcFile, rat('\', lcFile)))

Robert
Previous
Reply
Map
View

Click here to load this message in the networking platform