×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    Regular Contributor
    Join Date
    Jun 2009
    Posts
    179

    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.

  2. #2
    Super Contributor
    Join Date
    Jun 2006
    Location
    India
    Posts
    3,037

    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.

  3. #3
    Nokia Developer Expert
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,143

    Re: How to have a string array in Symbian

    I would use CDesCArray's like CDesCArrayFlat would be nice for the purpose.

  4. #4
    Super Contributor
    Join Date
    May 2005
    Location
    Hyderabad,India
    Posts
    704

    Re: How to have a string array in Symbian

    Hi Nikita,

    You can use CDesCArray or CArrayFixFlat<TDesC> or RPointerArray<TDesC>. Just go through the wiki examples for how to use the dynamic arrays or go through the example in SDK: Examples\Base\ArraysAndLists

    Thanks,
    Eswar

  5. #5
    Regular Contributor
    Join Date
    Jun 2009
    Posts
    179

    Re: How to have a string array in Symbian

    Thanks guys I have solved my problem.

  6. #6
    Nokia Developer Champion
    Join Date
    Oct 2007
    Location
    જુનાગઢ - India
    Posts
    3,034

    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.

  7. #7
    Regular Contributor
    Join Date
    Jun 2009
    Posts
    179

    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 enumsin the same way.

    Suppose I have an enum

    HTML Code:
    enum abc{
    EHello,
    EHi,
    EHiHello
    };
    Now how can I use it in the for loop.

  8. #8
    Nokia Developer Champion
    Join Date
    Oct 2007
    Location
    જુનાગઢ - India
    Posts
    3,034

    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??

  9. #9
    Regular Contributor
    Join Date
    Jun 2009
    Posts
    179

    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 text field of my structure which I have done with your help ,now in that structure I have command ID field 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 enums in my for loop

  10. #10
    Super Contributor
    Join Date
    May 2005
    Location
    Hyderabad,India
    Posts
    704

    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.
    Thanks,
    Eswar

  11. #11
    Regular Contributor
    Join Date
    Jun 2009
    Posts
    179

    Re: How to have a string array in Symbian

    Sorry I didn't get your logic. In my structure i have iText and iCommandID. Now in the for loop the strings I have added to the iText but how to add the enums to that iCommandID is my problem.

    Let me show you my code

    HTML Code:
    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
    ....
    Now this is my problem how will I put the enums there

  12. #12
    Nokia Developer Champion
    Join Date
    Oct 2007
    Location
    જુનાગઢ - India
    Posts
    3,034

    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
    }
    
    }

  13. #13
    Nokia Developer Expert
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,143

    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]

  14. #14
    Regular Contributor
    Join Date
    Jun 2009
    Posts
    179

    Re: How to have a string array in Symbian

    I tried to do that but when I debugged I got Panic EIKCOCTL 8. This is what I did as you suggested. My enums were

    HTML Code:
    enum abc
    {
    Hi=0,
    Hello,
    HelloHi
    };
    Then I created an variable array to my structure as SData data4[3];. Then in the for loop I did this

    HTML Code:
    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;
    
    ..
    ....

  15. #15
    Super Contributor
    Join Date
    May 2005
    Location
    Hyderabad,India
    Posts
    704

    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;
     
    ...
    Thanks,
    Eswar

Similar Threads

  1. How do we send and receive string array via bluetooth in J2ME
    By rahulkrishna in forum Mobile Java General
    Replies: 2
    Last Post: 2009-06-04, 01:50
  2. A question about String Literal in Symbian
    By AllenZhu in forum Symbian
    Replies: 1
    Last Post: 2009-05-26, 10:48
  3. Replies: 2
    Last Post: 2008-02-19, 07:15
  4. Symbian and non Symbian J2ME
    By thongtom in forum Mobile Java General
    Replies: 2
    Last Post: 2005-06-28, 10:52
  5. Replies: 1
    Last Post: 2003-12-19, 19:48

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •