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

Array of chars

Hi,

I want to use an array str, while each array element str[i]
is an array of chars of fixed length, say 40;

The best way to handle this in C# is StringBuilder I guess,
but as legacy C++ code must communicate with my C# app, I
prefer only low-level primitive types, so chars here.

Of course, char [] str = new char[40]; will create an array
of 40 chars for me, but that's not what I want.

I need something like :

for (int i=0;i<50;i++)
{
char [] str[i] = new char[40];
}
I guess, but how to dimension the array str itself. By
using char [] [] .... ????

Confused with the double dimensions, one for the array
lenght of str , and one for the number of chars in each
array element ...

Some help would be nice.

Thanks,
Peter

Nov 16 '05 #1
4 1887
Peter wrote:
Hi,

I want to use an array str, while each array element str[i]
is an array of chars of fixed length, say 40;

The best way to handle this in C# is StringBuilder I guess,
but as legacy C++ code must communicate with my C# app, I
prefer only low-level primitive types, so chars here.

Of course, char [] str = new char[40]; will create an array
of 40 chars for me, but that's not what I want.

I need something like :

for (int i=0;i<50;i++)
{
char [] str[i] = new char[40];
}
I guess, but how to dimension the array str itself. By
using char [] [] .... ????

Confused with the double dimensions, one for the array
lenght of str , and one for the number of chars in each
array element ...

Some help would be nice.

Thanks,
Peter


Do a search for multidimensional arrays in the MSDN library.

You want something like:
char[,] myArray = new char[10,40];
Nov 16 '05 #2
Peter wrote:
Hi,

I want to use an array str, while each array element str[i]
is an array of chars of fixed length, say 40;
(abridged)
I need something like :

for (int i=0;i<50;i++)
{
char [] str[i] = new char[40];
}

You've got two options. If every char array is the same length, eg. 40.
You can use a multidimensional array:
char[,] str=new char[40,40];

If the arrays aren't the same length, you must use a jagged array which
is an array-of-arrays.
char[][] str=new char[40][];
for (int i=0; i<40;i++) {
str[i]=new string[i*2];
}

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
Nov 16 '05 #3
Peter <An*****@work.nl> wrote:
I want to use an array str, while each array element str[i]
is an array of chars of fixed length, say 40;

The best way to handle this in C# is StringBuilder I guess,
but as legacy C++ code must communicate with my C# app, I
prefer only low-level primitive types, so chars here.

Of course, char [] str = new char[40]; will create an array
of 40 chars for me, but that's not what I want.

I need something like :

for (int i=0;i<50;i++)
{
char [] str[i] = new char[40];
}
I guess, but how to dimension the array str itself. By
using char [] [] .... ????

Confused with the double dimensions, one for the array
lenght of str , and one for the number of chars in each
array element ...


char[][] str = new char[50][];

for (int i=0; i < 50; i++)
{
str[i] = new char[40];
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
Jon,

I was waiting for your answer because I thought there should be something
else, luckily for my self-coinfidence you did not show that as well. (And
still I am not sure)

:-)

Cor
Nov 16 '05 #5

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

Similar topics

4
by: JC | last post by:
hi i want to check a char in the char array public void characters(char chars, int start, int length) { if (chars!='/n' || chars((char)'/r')) { System.out.println("String read is " + new...
5
by: pandapower | last post by:
Hi, I know about the equivalence of pointer and arrays.But my doubt comes when its for multidimentional arrays.I have read the C faq but still have some doubts. Suppose I have a declaration as...
3
by: s.subbarayan | last post by:
Dear all, I encountered the following piece of program: #include <stdio.h> void strprint(char *str); void main() { char *spr="hello"; strprint(spr); }
7
by: Roman Mashak | last post by:
Hello, All! I wonder is it possible to define an array containing strings, not single characters? What I want is array 'table' that will have N elements, and every element is a strings tailoring...
2
by: Michael | last post by:
Hi, How to understand the difference between the following three. My understanding is the number in bracket minus one is the max number of chars to store in the char array , right? ...
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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)...
0
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...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.