Reputation: 127
I have a code to read data block inside MIFARE card.
The method rfidM1.ReadDataFromCardM1
will read a block and return value in string
.
string memQuery = string.Empty;
int i = 0, j = 0;
sector = 4;
block = 4;
for (i = 0; i < block; i++)
{
for (j = 0; j < sector; j++)
{
memQuery += rfidM1.ReadDataFromCardM1(Convert.ToByte(j), Convert.ToByte(i), _Key1) + ",";
}
}
My intention is concating memQuery
with comma. Example output here:
,0,,,,,True,,C0-12320,0,,,,,,
I concat memQuery
with various ways, for example, using +=
, StringBuilder
or ArrayList
but they didn't work because it always has an output like this when I put it in MessageBox.
,0
It looks like string after that 0
cannot concat with other string after it. Why?
Upvotes: 0
Views: 676
Reputation: 3037
My intention is concating memQuery with comma
Wel, first get rid of the ArrayList and replace it with var memQuery = new List<string>();
.
Inside your for-loops, decide what to with null or empty results. Add a null
or skip the Add or ...
And then when the memQuery is filled correctly, you can do
string result = string.Join(",", memQuery);
string.Join()
can handle null
s in the input sequence.
Upvotes: 1