Jump to content
Sign in to follow this  
sbrady

parsing a file name

Recommended Posts

sbrady

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
JLogan3o13

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

√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
mikell

An other way

$res = StringRegExp("AR123 score v1 GM111n1.txt", '\h(\w+)\.', 1)
MsgBox(0, "", $res[0])
But as JLogan3o13 said this is specific

Share this post


Link to post
Share on other sites
kylomas

sbrady,

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)

kylomas

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  

×