Jump to content
Sign in to follow this  

parsing a file name

Recommended Posts

my need is to extract the last word from a file name. He is an example:

AR123 score v1 GM111n1.txt

how can I get GM111n1 from the file name. Thanks for any help you are willing to provide.

Share this post

Link to post
Share on other sites

Hi, sbrady. There are a number of ways to do what you want. Is the portion you are going to remove always the same length? Are there always the same number of characters before the portion you want to pull out? Is it always a .txt file? Are they always separated by a space? The answer to these questions affect how you would go about it. Just one example, if the portion you want is always the last bit, and they're always separated by a space, you could do this:

Local $aArray = StringSplit("AR123 score v1 GM111n1.txt", " ")
MsgBox(0, "", StringTrimRight($aArray[4], 4))

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Share this post

Link to post
Share on other sites


Given your string, this is slightly more flexible in that the number of words in the file does not need to be known. However, there is NO way to provide a complete solution without the answers to JL's questions.

local $str = 'AR123 score v1 GM111n1.txt'
local $aRet = stringregexp($str,'\s+(\w+)\.',3)
ConsoleWrite($aRet[0] & @LF)


edit: "Ah, yes...slow fingers, again.."

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...