473,770 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

possibe to delete string from string[] ?

I wanted to truncate a string array by removing the last item.
"strResult.leng th = 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
2 2565
"Beemer Biker" <js*******@swri .eduwrote in message
news:D3******** *************** ***********@mic rosoft.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<stringinst ead. It still does that under the covers,
but up front you get nice things like Remove().
Nov 19 '08 #2
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(l st.Count - 1)".
--
Stanimir Stoyanov
http://stoyanoff.info

"Beemer Biker" <js*******@swri .eduwrote in message
news:D3******** *************** ***********@mic rosoft.com...
>I wanted to truncate a string array by removing the last item.
"strResult.len gth = 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2586
by: I am Sam | last post by:
I keep getting this error and I don't know why: The path is too long after being fully qualified. Make sure path is less than 260 characters. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.IO.PathTooLongException: The path is too long
2
4137
by: andy | last post by:
Hi I have a requirement to submit form data to a url after collecting the data from the database. For example I need to send firstname and lastname through a post method I can call on the fly.
3
4653
by: silver360 | last post by:
Hello, I'm trying to create a basic Heap manager and i have some question about new/delete overloading. The following code give me this output : >> $./heap >> registered : 0x804d098 >> 0x804d008 _Delete unknown block >> registered : 0x804d138 >> 0x804d008 _Delete unknown block >> 0x804d098 _Delete ok
19
2608
by: Xavier Décoret | last post by:
Hi, I long thought one could not delete a const pointer but the following code compiles under g++ and visual net: class Dummy { public: Dummy() {} ~Dummy() {}
6
281
by: Nethali | last post by:
Hi all, Please explain me the following: I have struct as follows: struct Link { void* data; Link* next;
5
3944
by: sh26 | last post by:
I can Add and Delete (A, CName, MX and TXT) Dns records on the Dns Server using C# code. The problem I am having is if someone manaully creates a TXT record on the Dns Server, I cannot delete that particular record using the same C# code. Here is what I am using to delete the records: public void DeleteRecord(string domain, string recordName, string recordType, string recordData) { try { ...
7
6943
by: ITAutobot25 | last post by:
My delete button is not working in my GUI and my due date is today before midnight. Can anyone show me how to correct this error? My assignment statement is below as well as 5 classes. InventoryGUI is the main class to begin execution. Thanks! • Modify the Inventory Program to include an Add button, a Delete button, and a Modify button on the GUI. These buttons should allow the user to perform the corresponding actions on the item name, the...
1
2338
by: jmarcrum | last post by:
Hello all! i have a “monitor-type” program, where my program recognizes my defined "commands”, and executes the given command, or produces an error message that says “unrecognized command”. After execution or error message, the program puts the cursor on the next line, and waits for the next command. i have two commands that I CANNOT SEEM TO GET TO WORK...addDVD and deleteDVD. I just learned that I can't use an array, because i "must"...
2
2483
by: Danielle | last post by:
Hello all - Thank you in advance for any help you are able to provide. I am populating a gridview from a stored procuedure. The returned data is a name, phone number, email and guid of a contact in our database. I also need to use the Edit and Delete funtions in the gridview. Neither seems to be working as intended.
0
9617
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10257
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10099
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10037
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9904
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.