Length of string in array

  • Thread starter Thread starter Michael C
  • Start date Start date
M

Michael C

I have an array of strings

string[] strArray = new string[10];

strArray[5] = "ABC";

How can I determine the number of characters in the array item?

if (strArray[5].length = = 3)
{
}

This is acually returning 10 which is the array length

I want the array item string.length

Thanks

Michael
 
That is correct though...

Console.WriteLine(strArray[5].Length);

That should return 3.

Maybe you called strArray.Length without an indexer?

--
HTH

Kyril Magnos
"I'm not a developer anymore, I'm a software engineer now!" :-)

|I have an array of strings
|
| string[] strArray = new string[10];
|
| strArray[5] = "ABC";
|
| How can I determine the number of characters in the array item?
|
| if (strArray[5].length = = 3)
| {
| }
|
| This is acually returning 10 which is the array length
|
| I want the array item string.length
|
| Thanks
|
| Michael
|
|
 
Maybe try something like (strArray[5]).Length.

This should make no difference, does it :)

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk
Peter Rilling said:
Maybe try something like (strArray[5]).Length.


Michael C said:
I have an array of strings

string[] strArray = new string[10];

strArray[5] = "ABC";

How can I determine the number of characters in the array item?

if (strArray[5].length = = 3)
{
}

This is acually returning 10 which is the array length

I want the array item string.length

Thanks

Michael
 
You are right that it should not, but since the problem was that Length was
being applied to the array rather then the array element, this was all that
I could think of. There is nothing like being explicit when troubleshooting
code.


cody said:
Maybe try something like (strArray[5]).Length.

This should make no difference, does it :)

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk
Peter Rilling said:
Maybe try something like (strArray[5]).Length.


Michael C said:
I have an array of strings

string[] strArray = new string[10];

strArray[5] = "ABC";

How can I determine the number of characters in the array item?

if (strArray[5].length = = 3)
{
}

This is acually returning 10 which is the array length

I want the array item string.length

Thanks

Michael
 
Peter Rilling said:
You are right that it should not, but since the problem was that
Length was being applied to the array rather then the array element,
this was all that I could think of. There is nothing like being
explicit when troubleshooting code.

I think the problem is that we weren't seeing the actual code. The code
posted certainly wouldn't compile (due to the space in the comparison)
so I suspect it wasn't the real code.
 
Back
Top