General information
Category:
Coding, syntax & commands
>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
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only