473,327 Members | 1,896 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,327 software developers and data experts.

Combining 2 string arrays

I am looking for a way to combine 2 string arrays.

I am trying to get a list of files from 2 directories and combine them:

string[] strFiles;
string[] strFiles2;

strFiles = Directory.GetFiles(Settings.ArchiveFilePath, "*.*");
strFiles2 = Directory.GetFiles(Settings.ExceptionFilePath,
"*.*");

One way I was looking at was to copy them into a string collection:

List<stringsarray = new List<string>();

How would I get the string arrays into the collection? Do I need to do 2
loops and move them in one at a time?

Thanks,

Tom
Jul 25 '08 #1
6 3428
On Fri, 25 Jul 2008 14:30:13 -0700, tshad <ts***@dslextreme.comwrote:
[...]
How would I get the string arrays into the collection? Do I need to do 2
loops and move them in one at a time?
See List.AddRange():
http://msdn.microsoft.com/en-us/library/z883w3dc.aspx

For example:

List<stringsarray = new List<string>(strFiles.Length +
strFiles2.Length);

sarray.AddRange(strFiles);
sarray.AddRange(strFiles2);

Pete
Jul 25 '08 #2
tshad wrote:
I am looking for a way to combine 2 string arrays.

I am trying to get a list of files from 2 directories and combine them:

string[] strFiles;
string[] strFiles2;

strFiles = Directory.GetFiles(Settings.ArchiveFilePath, "*.*");
strFiles2 = Directory.GetFiles(Settings.ExceptionFilePath,
"*.*");

One way I was looking at was to copy them into a string collection:

List<stringsarray = new List<string>();

How would I get the string arrays into the collection? Do I need to do 2
loops and move them in one at a time?
List<stringsarray = strFiles.Concat(strFiles2).ToList();

Alun Harford
Jul 25 '08 #3
Both look pretty good.

Thanks,

Tom

"Alun Harford" <de*****@alunharford.co.ukwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
tshad wrote:
>I am looking for a way to combine 2 string arrays.

I am trying to get a list of files from 2 directories and combine them:

string[] strFiles;
string[] strFiles2;

strFiles = Directory.GetFiles(Settings.ArchiveFilePath,
"*.*");
strFiles2 = Directory.GetFiles(Settings.ExceptionFilePath,
"*.*");

One way I was looking at was to copy them into a string collection:

List<stringsarray = new List<string>();

How would I get the string arrays into the collection? Do I need to do 2
loops and move them in one at a time?

List<stringsarray = strFiles.Concat(strFiles2).ToList();

Alun Harford

Jul 29 '08 #4
Spoke a little too soon.

Apparently, strFiles.Concat(...) isn't valid.

Do I need another using statement other than using System?

Thanks,

Tom

"tshad" <ts***@dslextreme.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Both look pretty good.

Thanks,

Tom

"Alun Harford" <de*****@alunharford.co.ukwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>tshad wrote:
>>I am looking for a way to combine 2 string arrays.

I am trying to get a list of files from 2 directories and combine them:

string[] strFiles;
string[] strFiles2;

strFiles = Directory.GetFiles(Settings.ArchiveFilePath,
"*.*");
strFiles2 = Directory.GetFiles(Settings.ExceptionFilePath,
"*.*");

One way I was looking at was to copy them into a string collection:

List<stringsarray = new List<string>();

How would I get the string arrays into the collection? Do I need to do
2 loops and move them in one at a time?

List<stringsarray = strFiles.Concat(strFiles2).ToList();

Alun Harford


Jul 29 '08 #5
tshad wrote:
Spoke a little too soon.

Apparently, strFiles.Concat(...) isn't valid.

Do I need another using statement other than using System?
You need C# 3 for that one, and

using System.Linq;

Alun Harford
Aug 1 '08 #6
On Jul 26, 1:30*am, "tshad" <ts...@dslextreme.comwrote:
I am looking for a way to combine 2 string arrays.

I am trying to get a list of files from 2 directories and combine them:

* * * * * * string[] strFiles;
* * * * * * string[] strFiles2;

* * * * * * strFiles = Directory.GetFiles(Settings.ArchiveFilePath, "*.*");
* * * * * * strFiles2 = Directory.GetFiles(Settings.ExceptionFilePath,
"*.*");

One way I was looking at was to copy them into a string collection:

* * * * * * List<stringsarray = new List<string>();

How would I get the string arrays into the collection? *Do I need to do2
loops and move them in one at a time?
If you're okay with having array as a result, here's another one:

string[] sarray = new string[strFiles.Length + strFiles2.Length];
strFiles.CopyTo(sarray, 0);
strFiles2.CopyTo(sarray, strFiles.Length);
Aug 1 '08 #7

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

Similar topics

2
by: Chris Mullins | last post by:
I've spent a bit of time over the last year trying to implement RFC 3454 (Preparation of Internationalized Strings, aka 'StringPrep'). This RFC is also a dependency for RFC 3491...
10
by: mike | last post by:
If I have 2 object arrays like: var txtobj = theform.getElementsByTagName("input"); var selobj = theform.getElementsByTagName("select"); and i want to iterate over them I'd like to combine...
16
by: Don Starr | last post by:
When applied to a string literal, is the sizeof operator supposed to return the size of the string (including nul), or the size of a pointer? For example, assuming a char is 1 byte and a char *...
1
by: Mr. Jingles | last post by:
Hi, anyone have any thoughts on combining two 2-Dimensional arrays into one. Thanx
1
by: ferraro.joseph | last post by:
Hi, I'm querying Salesforce.com via their AJAX toolkit and outputting query results into a table. Currently, their toolkit does not possess the ability to do table joins via their structured...
1
by: Jeff | last post by:
I have two array: var Array1=new Array(); Array1=,,]; Array1=,,]; var Array2=new Array(); Array2=,,];
3
by: =?Utf-8?B?U1MgbWFkaHU=?= | last post by:
Hi, I have two word files. listprice.doc,product.doc I converted each of the documents into bytes byte bytedata - lisprice.doc byte bytedata1-product.doc I create a new array and copy both...
3
by: Ken Fine | last post by:
This is a question that someone familiar with ASP.NET and ADO.NET DataSets and DataTables should be able to answer fairly easily. The basic question is how I can efficiently match data from one...
8
by: rodeored | last post by:
I don't know what the official programming lingo is for this situation but there probably is one. I have arrays, which happen to be parsed urls, and I want to make one big array with each subarray...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.