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]];

}

1 Answer 1

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 /.

5
  • Actually, I believe it would give you Downloads/Movies/HD-Movies (without the first slash) Mar 14, 2013 at 17:50
  • +1: Nice answer. I like you used a method on NSArray instead of looping through the values. Mar 14, 2013 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, 2013 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, 2013 at 18:26
  • yes, make a subarray with range having one less, and then do the same componentsJoinedByString: Mar 14, 2013 at 18:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.