sbrady Posted May 3, 2013 Share Posted May 3, 2013 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. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted May 3, 2013 Moderators Share Posted May 3, 2013 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! Link to comment Share on other sites More sharing options...
mikell Posted May 3, 2013 Share Posted May 3, 2013 An other way$res = StringRegExp("AR123 score v1 GM111n1.txt", '\h(\w+)\.', 1) MsgBox(0, "", $res[0])But as JLogan3o13 said this is specific Link to comment Share on other sites More sharing options...
kylomas Posted May 3, 2013 Share Posted May 3, 2013 (edited) 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 May 3, 2013 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now