C# - remove part of listbox items -


i have listbox has collection of files directory , need remove extension them. m4a format should make bit easier. have searched , cannot find solution.

i new programming , appreciate help. if request example appreciate , please use lstsong instead of placeholder because confused whats placeholder , not in examples.

as requested code writes it:

string[] songspaths = system.io.directory.getfiles(librarypath + "/" + albumpath + "/" + songpath);  list<string> listsongs = new list<string>();  foreach (var f in songspaths) {    string songs = f.split('\\').last();    lstsong.items.add(songs); } 

i unsure how code works. understand of written friend me. why going afterwards. again.

understanding comment need filename of files, without path or extension. can use path.getfilenamewithoutextension

string[] songspaths = system.io.directory.getfiles(librarypath + "/" + albumpath + "/" + songpath); // files specified directory  list<string> listsongs = new list<string>();  foreach (var f in songspaths) {    lstsong.items.add(path.getfilenamewithoutextension(f)); // store filename without path or extension in list } 

and explain code friend has wrote:

string songs = f.split('\\').last(); 

the string.split method diviedes string array of substrings delimited given character. in case it's (escaped) backslash. .last() returns last element of array.


Comments

Popular posts from this blog

How to logout from a login page in asp.net -

Stack level too deep error after upgrade to rails 3.2 and ruby 1.9.3 -