2

I need to create a NSString for browsing folders in FTP share. i show the directory on a TableView, and user´s can browse by selecting row ´s

Im writing the string of selected rows into a mutable array, and then i need to make a string of all strings in the mutable array. means add the last string to the previous when the row is selected

for example first string in array is "Downloads" second "Movies" third "HD-Movies"....... and so on for that i need the string on the first time selected row "/Downloads/" the second time "/Downloads/Movies/", an the third "/Downloads/Movies/HD-Movies"

i´m sure i need a NSMutableString, but don´t know how to add the strings...

here a part of my code:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

NSMutableArray *filePathArray = [[NSMutableArray alloc]init];
[filePathArray addObject:@"/Downloads/"];
[filePathArray addObject:[fileNameArray objectAtIndex:indexPath.row]];

}
Alladinian
  • 34,483
  • 6
  • 89
  • 91
HugoBoss
  • 95
  • 3
  • 11

1 Answers1

4

You can do like this:

NSString *string=[array componentsJoinedByString:@"/"];

This will give you :

Downloads/Movies/HD-Movies

Now if you want / in front than you can simply append an /.

Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
  • Actually, I believe it would give you `Downloads/Movies/HD-Movies` (without the first slash) – JRG-Developer Mar 14 '13 at 17:50
  • +1: Nice answer. I like you used a method on `NSArray` instead of looping through the values. – JRG-Developer Mar 14 '13 at 17:52
  • the first time i select the row (Movies) the string is /downloads/movie/, the second time i select a row (HD-Movies) i get the string /downloads/HD-Movies (movie missing); componentsJoinedByString add´s just the last string to the first... – HugoBoss Mar 14 '13 at 18:16
  • so, fixed it... the init of the array in viewwillappear, and the static Download path also! is there a way to remove the last added string? (for a back button) – HugoBoss Mar 14 '13 at 18:26
  • yes, make a subarray with range having one less, and then do the same componentsJoinedByString: – Anoop Vaidya Mar 14 '13 at 18:27