Question Array Value Removal problem

mBe

New member
Joined
Feb 18, 2009
Messages
3
Programming Experience
1-3
Hi guys,

I got a small problem with an array where I simply do not know how I could solve that issue. Im currently working on a backup program and want to read file paths into an array, for that I created a text file containing all paths of my folders separated by "|"'s

Example: "folderpath1\blablabla|folderpath2\blublublub|"

Unfortunately I also got a | at the end of the last path, meaning if I read that now into an array, the last array data will just be an empty string.

arrayproblem.jpg


Now my question is, how can I remove that last position of my array the best? Or is there a way to just ignore the last position when filling data into the array?

Thanks in advance for your help :)
 
You can remove the final "|" before you do the split:

if temp.SubString(temp.length - 1, 1) = "|" then
array = temp.SubString(0, temp.length - 1).Split("|")
else
array = temp.Split("|")
end if
 
or you could just do

VB.NET:
array = temp.Split("|",StringSplitOptions.RemoveEmptyEntries)

which will drop the empty entries
 
Back
Top