By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,616 Members | 2,026 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,616 IT Pros & Developers. It's quick & easy.

Extract filenames from a string

P: 45
hi all...

i have got arequirement where in i need to take out the file names alone from a given string... i thought of using indexof function but not sure of its exact usage...

eg

there are two paths like this

str="c:\windows\temp c:\windows\dir"

i need to get the file names alone as outputs that is temp and dir...

i tried giving the index of fuction like this but its not working

int len
len=str.indexof(" ")
string str1
str1=str.substring(0,len)


but this code is not working...can anyone suggest me a solution..

wiill be thankful to whatever help i get

thanks

sairaam
May 8 '07 #1
Share this Question
Share on Google+
5 Replies


Expert 5K+
P: 8,434
The Split() function will allow you to split the string at a given character (such as a space). However, this might be a problem if the filenames contain spaces.
May 8 '07 #2

P: 45
The Split() function will allow you to split the string at a given character (such as a space). However, this might be a problem if the filenames contain spaces.
THANKS FOR UR HELP...I DONT CLEARLY GET YOU..CAN YOU QUOTE ME WITH SOME EXAMPLE... IT WOULD BE STILL MORE HELPFUL..

SAIRAAM
May 8 '07 #3

P: 3
this will like this
str=strreverse(str)
str=mid(str,1,instr(1,str,"/")-1)
str=strreverse(str)
it will help u
May 8 '07 #4

Expert 5K+
P: 8,434
Here's a very simple example (from VB6) of how the Split() function can be used to pull the string apart...
Expand|Select|Wrap|Line Numbers
  1. Debug.Print Split("c:\windows\temp c:\windows\dir", " ")(0)
  2. Debug.Print Split("c:\windows\temp c:\windows\dir", " ")(1)
May 8 '07 #5

P: 45
Here's a very simple example (from VB6) of how the Split() function can be used to pull the string apart...
Expand|Select|Wrap|Line Numbers
  1. Debug.Print Split("c:\windows\temp c:\windows\dir", " ")(0)
  2. Debug.Print Split("c:\windows\temp c:\windows\dir", " ")(1)
thanks a lot sir i am able to get it now... thanks for your guidence

sairaaam
May 8 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.