How to have a string array in Symbian
Hi I am new to symbian I want to have a string array and want to use it in a for loop but dont know how to create it. Any example will help me a lot. Suppose I have three strings "Alice","Jeneffer","Christine" .How to make an array of this in Symbian. Is HBuf or TArray will do I am confused.
Re: How to have a string array in Symbian
Hi,
You can use HBuf as well but the simple way is:
TBuf<32> st[3];
st[1].Copy(_L("Alice"));
st[2].Copy(_L("Jeneffer"));
st[3].Copy(_L("Christine"));
for(TInt i=0; i<3; i++)
{
use st[i]...
}
hope this will help you. You can use HBuf also.
Re: How to have a string array in Symbian
I would use CDesCArray's like CDesCArrayFlat would be nice for the purpose.
Re: How to have a string array in Symbian
Hi Nikita,
You can use [B]CDesCArray[/B] or [B]CArrayFixFlat<TDesC>[/B] or [B]RPointerArray<TDesC>[/B]. Just go through the wiki examples for how to use the dynamic arrays or go through the example in SDK: [COLOR="Blue"]Examples\Base\ArraysAndLists[/COLOR]
Thanks,
Eswar
Re: How to have a string array in Symbian
Thanks guys I have solved my problem.
Re: How to have a string array in Symbian
I would prefer CDesCArray or CArrayFixFlat, if frequently modification in string is not required. If strings in array need to be updated/deleted/removed frequently then i would prefer RPointerArray.
Re: How to have a string array in Symbian
Sorry to disturb you again guys...but can you help me on this..
As you have guided me how to create an array of strings and use them in a for loop can you help me how to use [B]enums[/B]in the same way.
Suppose I have an [B]enum[/B]
[HTML]
enum abc{
EHello,
EHi,
EHiHello
};
[/HTML]
Now how can I use it in the for loop.
Re: How to have a string array in Symbian
You are appending string to array in a loop, what do you want to do with enum in loop??
Re: How to have a string array in Symbian
Actually those strings will have some enums related to it. I am maintaining a structure out here .Well it is a bit complicated to explain. The strings in the array are assigned to the [B]text field[/B] of my structure which I have done with your help ,now in that structure I have [B]command ID[/B] [B]field[/B] where I have to use those enums. In other language these enums will have to be related to teh strings. I am not sure whether you got or not . But please if you can help me how to use those [B] enums[/B] in my [B]for loop[/B]
Re: How to have a string array in Symbian
Hi,
Just do as follows:
[CODE]
//your structure declaration
struct TMyStruct
{
TBuf<50> str;
abc aaa;
};
//Declare the dynamic array as follows:
RPointerArray<TMyStruct>;
or
CArrayFixFlat<TMyStruct>;
//And append the structures to the array.
[/CODE]
Thanks,
Eswar
Re: How to have a string array in Symbian
Sorry I didn't get your logic. In my structure i have [B]iText[/B] and [B]iCommandID[/B]. Now in the for loop the strings I have added to the [B]iText[/B] but how to add the enums to that [B]iCommandID[/B] is my problem.
Let me show you my code
[HTML]
SData data4[3];//SData is my structure.
TBuf<32> st[3];
st[0].Copy(_L("Alice"));
st[1].Copy(_L("Jennefer"));
st[2].Copy(_L("Christine"));
for(TInt i=0;i<3;i++)
{
data4[i].iText=st[i];
...
...
data4[i].iCommandL = ????//Here I have to put the enums
....
[/HTML]
Now this is my problem how will I put the enums there
Re: How to have a string array in Symbian
Enum is basically named constant and you can not use it in this way. what you can do is initialize first member of with 0 so you can compare it in a loop as follows.
I guess you want to use enum like following.
[CODE]
for (int i = 0; i <adfasd; i++)
{
if(i==EDynamicMenu1) // or you can use switch case here
{
//bhah blah
//control 1
}
else if(i==EDynamicMenu2)
{
//bhah blah
//control 2
}
}[/CODE]
Re: How to have a string array in Symbian
hmm, we seem to have this discussion in two separate threads, anyway, answering the same in both, so why not just use the enums instead the numbers in the i.e. st[0] -->st[EEnumOne]
Re: How to have a string array in Symbian
I tried to do that but when I debugged I got [B]Panic EIKCOCTL 8[/B]. This is what I did as you suggested. My enums were
[HTML]
enum abc
{
Hi=0,
Hello,
HelloHi
};
[/HTML]
Then I created an variable array to my structure as [B]SData data4[3];[/B]. Then in the [B]for loop[/B] I did this
[HTML]
for(TInt i=0;i<3;i++)
{
if (i == Hi)
data4[i].iCommandId = Hi;
else if (i == Hello)
data4[i].iCommandId = Hello;
else if (i == HelloHi)
data4[i].iCommandId = HelloHi;
..
....
[/HTML]
Re: How to have a string array in Symbian
Hi Nikita,
Just try like this:
[CODE]
for(TInt i=0;i<3;i++)
{
data4[i].iCommandId = i;
...
[/CODE]
Thanks,
Eswar