473,395 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

String redimming

I have a string(10) array.

I want to redim it so that I only have the last 9 strings in the array.
What is the best way to do this?
Example:
String(0) = Dog
String(1) = Cat
String(2) = Bird

I want the cat, and bird to remain and drop the dog from the array....
-Peter

Nov 21 '05 #1
5 1297
Something like this might help, although it's hardcoded:

Dim str(5)
str(0) = "Dog"
str(1) = "Bird"
str(2) = "Cat"
str(3) = "Horse"
str(4) = "Lion"

Dim x
For x = 0 To 3
str(x) = str(x + 1)
Next
str(4) = ""
ReDim Preserve str(4)

"pmclinn" <pm*****@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
I have a string(10) array.

I want to redim it so that I only have the last 9 strings in the array.
What is the best way to do this?
Example:
String(0) = Dog
String(1) = Cat
String(2) = Bird

I want the cat, and bird to remain and drop the dog from the array....
-Peter

Nov 21 '05 #2
"pmclinn" <pm*****@gmail.com> schrieb:
I have a string(10) array.

I want to redim it so that I only have the last 9 strings in the array.
What is the best way to do this?
Example:
String(0) = Dog
String(1) = Cat
String(2) = Bird

I want the cat, and bird to remain and drop the dog from the array....


Using 'ReDim Preserve' you can only remove items from the end of the array.
However, you can use 'Array.Copy' to create a copy of the array and then
discard the original array.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3
pmclinn,
In addition to the other comments.

Rather then use an Array, consider using an ArrayList (.NET 1.0 & 1.1) or
List(Of T) (.NET 2.0).

Then you can use ArrayList.RemoveAt(0) or List(Of String).RemoveAt(0) to
remove the first element in the "array".

http://msdn.microsoft.com/library/de...oveAtTopic.asp

http://msdn2.microsoft.com/en-us/lib...US,VS.80).aspx

Something like:

' VB 2003 syntax
Dim list As New ArrayList
list.Add("Dog")
list.Add("Cat")
list.Add("Bird")
list.RemoveAt(0)

' VB 2005 syntax
Dim list As New List(Of String)
list.Add("Dog")
list.Add("Cat")
list.Add("Bird")
list.RemoveAt(0)

--
Hope this helps
Jay [MVP - Outlook]
T.S. Bradley - http://www.tsbradley.net
"pmclinn" <pm*****@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
|I have a string(10) array.
|
| I want to redim it so that I only have the last 9 strings in the array.
| What is the best way to do this?
|
|
| Example:
| String(0) = Dog
| String(1) = Cat
| String(2) = Bird
|
| I want the cat, and bird to remain and drop the dog from the array....
|
|
| -Peter
|
Nov 21 '05 #4

"Jay B. Harlow [MVP - Outlook]" <Ja************@tsbradley.net> wrote in
message news:Ou*************@TK2MSFTNGP09.phx.gbl...
pmclinn,
In addition to the other comments.

Rather then use an Array, consider using an ArrayList (.NET 1.0 & 1.1) or
List(Of T) (.NET 2.0).


And since you are only using strings, try StringCollection (under the
System.Collections.Specialized namespace) :)

HTH,
Mythran

Nov 21 '05 #5
Mythran,
Yes!

StringCollection is a very good option in this case, as it covers .NET 1.0,
1.1 & 2.0!

--
Hope this helps
Jay [MVP - Outlook]
T.S. Bradley - http://www.tsbradley.net
"Mythran" <ki********@hotmail.comREMOVETRAIL> wrote in message
news:OO**************@TK2MSFTNGP14.phx.gbl...
|
| "Jay B. Harlow [MVP - Outlook]" <Ja************@tsbradley.net> wrote in
| message news:Ou*************@TK2MSFTNGP09.phx.gbl...
| > pmclinn,
| > In addition to the other comments.
| >
| > Rather then use an Array, consider using an ArrayList (.NET 1.0 & 1.1)
or
| > List(Of T) (.NET 2.0).
| >
|
| And since you are only using strings, try StringCollection (under the
| System.Collections.Specialized namespace) :)
|
| HTH,
| Mythran
|
Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Krakatioison | last post by:
My sites navigation is like this: http://www.newsbackup.com/index.php?n=000000000040900000 , depending on the variable "n" (which is always a number), it will take me anywhere on the site......
5
by: Stu Cazzo | last post by:
I have the following: String myStringArray; String myString = "98 99 100"; I want to split up myString and put it into myStringArray. If I use this: myStringArray = myString.split(" "); it...
9
by: John F Dutcher | last post by:
I use code like the following to retrieve fields from a form: recd = recd.append(string.ljust(form.getfirst("lname",' '),15)) recd.append(string.ljust(form.getfirst("fname",' '),15)) etc.,...
9
by: Derek Hart | last post by:
I wish to execute code from a string. The string will have a function name, which will return a string: Dim a as string a = "MyFunctionName(param1, param2)" I have seen a ton of people...
10
by: Angus Leeming | last post by:
Hello, Could someone explain to me why the Standard conveners chose to typedef std::string rather than derive it from std::basic_string<char, ...>? The result of course is that it is...
37
by: Kevin C | last post by:
Quick Question: StringBuilder is obviously more efficient dealing with string concatenations than the old '+=' method... however, in dealing with relatively large string concatenations (ie,...
2
by: Andrew | last post by:
I have written two classes : a String Class based on the book " C++ in 21 days " and a GenericIpClass listed below : file GenericStringClass.h // Generic String class
0
by: pmclinn | last post by:
I have a string(10) array. I want to redim it so that I only have the last 9 strings in the array. What is the best way to do this? Example: String(0) = Dog String(1) = Cat String(2) =...
16
by: Giles | last post by:
When assembling an HTML string from a database before sending it to the client (ie keeping the connection as short as possible), adding to an existing string (strOut=strOut & strNextLine) takes...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.