Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need to remove the ext of a file name 4

Status
Not open for further replies.
Jan 20, 2007
237
US
Hi Guys,
I have a variable that can hold something like this
lcjobno="1234.dbf" or "123459.dbf" or whatever i just need to get from that variable lcjobno w/o the dot and the dbf
so i am looking for getting just 1234 or 123459, this is just an example, i need whatever but not the ".dbf"
what command can i use
Thanks in advance
 

lcstem = juststem(lcjobno)

(see also justext(), justfname() and justpath() in the vfp help.)

nigel
 

Also,
*--Trim all leading and trailing blanks:
lcjobno= ALLTRIM(lcjobno)

lc_name= LEFT(lcjobno,LEN(lcjobno)-4)

Edgar
Integrated Bar Code Systems, INc.

Edgar
Integrated Bar Code Systems, Inc.
 
The advantage of Nigel's solution is that it won't fail if the string is not in the expected format, for example if the extension is missing or there is no dot. Edgar's code will always strip the last four characters from the string, regarless of the whether the format is correct.

By the way, a simpler form of Edgar's code would be

[tt]lc_name= SUBSTR(lcjobno, 1, 4)[/tt]

I'm not suggesting you should use this. JUSTSTEM() is the obvious solution.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Juststem has AllTrim() included. Also, it works with arbitrary file extensions, eg with jpeg your code would need to go back 5 chars to remove .jpeg, JustStem does that until the last dot in a string:

Code:
? "->"+JUSTSTEM("   abc.jpeg   ")+"<-"
output:->abc<-
The arrows just illustrate the removal of any spaces.

So JustStem() can be used with char fields storing file names, too, etc. - anything not coming "pure" in respect of leading or trailing spaces. All JUSTX() function are built that way. Of course, inner spaces, i.e. spaces in a path, are kept as is. So this is JustFine() (tm).

Bye, Olaf.

 
Juststem() is the way to go, as that can include the dot and any ext lenght thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top