0

I have string, in this form : folders = "{string1;string2;string3}". Each string(NR) represents the name of a directory. I have another variable, root, which holds the root path of the folder which contains the items in variable "folder". How can I initialize another variable, "fullPathFolders" of type List (Of String) with the values from variable "folders", having the root path appended to each string in the variable "folders"?

So I want something like this:

fullPathFolders = {rootPath + string1, rootPath + string2,rootPath + string3}

And I was wondering if something like this can be done:

 Dim fullPathFolders As List(Of String) = From {rootPath & fullPathFolders}

since it seems to me that it would be faster and easier than the classic method of using the String.Split method (or its equivalent in vb) and then parsing through the list of strings and adding manually at the beginning of each string the root path.

3
  • 2
    Surely it has got to be easier to just try it and see if it works, rather than post a question on here about it. By the time you have written the question you could have had the answer Commented Mar 3, 2014 at 9:39
  • I posted it here exactly because it doesn't work and wanted to see if there is somebody out there who knows a better method of achieving something like what I asked for (which was just a small exemplification of what I want to do and again, doesn't work, hence why I posted here). Now that this is out of the way, the question still stands and I would appreciate any suggestions since I am a beginner in vb. Commented Mar 3, 2014 at 9:44
  • If you read the message carefully, I proposed a solution at the bottom of my message, which I find a bit long and hoped that there is a simpler, faster and better one out there. I thought that this is a place for learning things related to programming, not to learn how to write proper text in the english language. If you have a solution to the problem I posted here, I would happily try it and then thank you sincerely. I would appreciate if the focus fell on my problem rather than my english skills. Commented Mar 3, 2014 at 9:56

1 Answer 1

2

Note that

folders = "{string1;string2;string3}"

is not a List of strings, it's a single String.

You probably want something like

Dim folders = New List(Of String) From {"string1", "string2", "string3"}

(If you can't change that code to use a List in the first place, creating a List out of this string is as easy as folders.SubString(1, folders.Length - 2).Split(";").


Then you can create the second list with something like

 Dim fullPathFolders = folders.Select(Function(s) rootPath & s).ToList()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.