INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

need to remove the ext of a file name

need to remove the ext of a file name

(OP)
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

RE: need to remove the ext of a file name


lcstem = juststem(lcjobno)

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

nigel

RE: need to remove the ext of a file name


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.

RE: need to remove the ext of a file name

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

lc_name= SUBSTR(lcjobno, 1, 4)

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

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: need to remove the ext of a file name

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.

RE: need to remove the ext of a file name

(OP)
Juststem() is the way to go, as that can include the dot and any ext lenght thanks

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close