By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,745 Members | 1,897 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,745 IT Pros & Developers. It's quick & easy.

possibe to delete string from string[] ?

P: n/a
I wanted to truncate a string array by removing the last item.
"strResult.length = n-1" does not work as the length is read only. I tried
strResult[n] = null and just got a null. Also tried strResult[n].Remove(0)
and all it did was delete characters, not remove the string. I can create a
string the correct size using "new string [n-1]" and then copy but it seems
there should be an easier way. I cant seem to make VS 2008 get me good help
on "string[]" It is not the same as StringBuilder and is just an array of
strings is it not?

...TIA..

Nov 19 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Beemer Biker" <js*******@swri.eduwrote in message
news:D3**********************************@microsof t.com...
I can create a string the correct size using "new string [n-1]" and then
copy but it seems there should be an easier way.
Nope. When working with a plain old array, that's all you get. You ought to
consider using List<stringinstead. It still does that under the covers,
but up front you get nice things like Remove().
Nov 19 '08 #2

P: n/a
By design arrays are of fixed side. I would suggest using a generic List of
strings: List<string>, which you can manipulate as you wish. Removing the
last item can be done by calling "lst.RemoveAt(lst.Count - 1)".
--
Stanimir Stoyanov
http://stoyanoff.info

"Beemer Biker" <js*******@swri.eduwrote in message
news:D3**********************************@microsof t.com...
>I wanted to truncate a string array by removing the last item.
"strResult.length = n-1" does not work as the length is read only. I tried
strResult[n] = null and just got a null. Also tried strResult[n].Remove(0)
and all it did was delete characters, not remove the string. I can create a
string the correct size using "new string [n-1]" and then copy but it seems
there should be an easier way. I cant seem to make VS 2008 get me good
help on "string[]" It is not the same as StringBuilder and is just an
array of strings is it not?

..TIA..
Nov 19 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.