dynamic string[]

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Spare Change

    dynamic string[]

    I am told that I can have a dynamic or static string array.

    So if I declare

    string[] dynamic;

    How do I add elements to dynamic and resize it ?




    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.752 / Virus Database: 503 - Release Date: 9/3/2004


  • Adam Clauss

    #2
    Re: dynamic string[]

    You can't - check out ArrayList.

    --
    Adam Clauss
    cabadam@tamu.ed u
    "Spare Change" <sparechange@sp am.spam> wrote in message news:ZXv_c.660$ ip2.326@newsrea d3.news.pas.ear thlink.net...[color=blue]
    >I am told that I can have a dynamic or static string array.
    >
    > So if I declare
    >
    > string[] dynamic;
    >
    > How do I add elements to dynamic and resize it ?
    >
    >
    >
    >
    > ---
    > Outgoing mail is certified Virus Free.
    > Checked by AVG anti-virus system (http://www.grisoft.com).
    > Version: 6.0.752 / Virus Database: 503 - Release Date: 9/3/2004
    >
    >[/color]

    Comment

    • Marijan Tadin

      #3
      Re: dynamic string[]

      Try Sytem.Text.Stri ngBuilder

      Marijan


      "Spare Change" <sparechange@sp am.spam> wrote in message
      news:ZXv_c.660$ ip2.326@newsrea d3.news.pas.ear thlink.net...[color=blue]
      > I am told that I can have a dynamic or static string array.
      >
      > So if I declare
      >
      > string[] dynamic;
      >
      > How do I add elements to dynamic and resize it ?
      >
      >
      >
      >
      > ---
      > Outgoing mail is certified Virus Free.
      > Checked by AVG anti-virus system (http://www.grisoft.com).
      > Version: 6.0.752 / Virus Database: 503 - Release Date: 9/3/2004
      >
      >[/color]

      Comment

      • The Devil

        #4
        Re: dynamic string[]


        I went with a resizing routine.

        foreach(Match m1 in mc1)
        {
        temp = new string[i+1];
        anchors.CopyTo( temp,0);
        temp[i++]=fileName+"#"+m 1.Value.Substri ng(5,m1.Length-5);
        anchors=temp;
        }


        Marijan Tadin wrote:
        [color=blue]
        > Try Sytem.Text.Stri ngBuilder
        >
        > Marijan
        >
        >
        > "Spare Change" <sparechange@sp am.spam> wrote in message
        > news:ZXv_c.660$ ip2.326@newsrea d3.news.pas.ear thlink.net...[color=green]
        >> I am told that I can have a dynamic or static string array.
        >>
        >> So if I declare
        >>
        >> string[] dynamic;
        >>
        >> How do I add elements to dynamic and resize it ?
        >>
        >>
        >>
        >>
        >> ---
        >> Outgoing mail is certified Virus Free.
        >> Checked by AVG anti-virus system (http://www.grisoft.com).
        >> Version: 6.0.752 / Virus Database: 503 - Release Date: 9/3/2004
        >>
        >>[/color][/color]

        --
        incognito http://kentpsychedelic.blogspot.com
        new material added 9/5

        Comment

        • Cor Ligthert

          #5
          Re: dynamic string[]

          Spare,

          You declare a "static" string as

          string[10] dynamic;

          A nice string with a fixed lenght with the name dynamic.

          For dynamic array typen check all the iList collections (from which is the
          fixex lenght array one)


          For even more have a look at the link iCollection on that bottom of that
          page

          I hope this helps?

          Cor


          Comment

          • Scott Allen

            #6
            Re: dynamic string[]

            Hi Cor:

            Just to avoid confusion:
            [color=blue]
            >You declare a "static" string as
            >
            >string[10] dynamic;[/color]

            The above would lead to a compiler error.

            This:

            string[] dynamic = new string[10];

            Would create a single dimensional array of string types.

            --
            Scott



            On Sun, 5 Sep 2004 12:12:34 +0200, "Cor Ligthert"
            <notfirstname@p lanet.nl> wrote:
            [color=blue]
            >Spare,
            >
            >You declare a "static" string as
            >
            >string[10] dynamic;
            >
            >A nice string with a fixed lenght with the name dynamic.
            >
            >For dynamic array typen check all the iList collections (from which is the
            >fixex lenght array one)
            >http://msdn.microsoft.com/library/de...classtopic.asp
            >
            >For even more have a look at the link iCollection on that bottom of that
            >page
            >
            >I hope this helps?
            >
            >Cor
            >[/color]

            Comment

            • Austin Ehlers

              #7
              Re: dynamic string[]

              On Sun, 05 Sep 2004 03:43:53 GMT, "Spare Change"
              <sparechange@sp am.spam> wrote:
              [color=blue]
              >I am told that I can have a dynamic or static string array.
              >
              >So if I declare
              >
              >string[] dynamic;
              >
              >How do I add elements to dynamic and resize it ?[/color]

              using System.Collecti ons.Specialized ;

              ....
              StringCollectio n sc=new StringCollectio n();
              sc.Add(str1);
              ....
              //get a real string[] when done if needed

              int len=sc.Count;
              string[] strings=new string[len];
              sc.CopyTo(strin gs,0);

              Austin Ehlers

              Comment

              • i will now proceed to entangle the entire area

                #8
                Re: dynamic string[]


                Yes, you are quite right.

                But, I read that string[] can be dynamic.

                I see no evidence, that once declared, that a primitive string[] can be
                'ReDim'ed

                :D

                Scott Allen wrote:
                [color=blue]
                > Hi Cor:
                >
                > Just to avoid confusion:
                >[color=green]
                >>You declare a "static" string as
                >>
                >>string[10] dynamic;[/color]
                >
                > The above would lead to a compiler error.
                >
                > This:
                >
                > string[] dynamic = new string[10];
                >
                > Would create a single dimensional array of string types.
                >
                > --
                > Scott
                > http://www.OdeToCode.com
                >
                >
                > On Sun, 5 Sep 2004 12:12:34 +0200, "Cor Ligthert"
                > <notfirstname@p lanet.nl> wrote:
                >[color=green]
                >>Spare,
                >>
                >>You declare a "static" string as
                >>
                >>string[10] dynamic;
                >>
                >>A nice string with a fixed lenght with the name dynamic.
                >>
                >>For dynamic array typen check all the iList collections (from which is the
                >>fixex lenght array one)
                >>http://msdn.microsoft.com/library/de...classtopic.asp
                >>
                >>For even more have a look at the link iCollection on that bottom of that
                >>page
                >>
                >>I hope this helps?
                >>
                >>Cor
                >>[/color][/color]

                Comment

                • Chad Chisholm

                  #9
                  Re: dynamic string[]

                  I don't know of any way in c# to implicitly resize a string array.
                  Consider using System.Collecti ons.Speciallize d.StringColleci on class.
                  It's a strongly-typed collection, something like an array list, but
                  for strings, so there is no performance hit for boxing.

                  Comment

                  • Scott Allen

                    #10
                    Re: dynamic string[]

                    Hi Cor:

                    Just to avoid confusion:
                    [color=blue]
                    >You declare a "static" string as
                    >
                    >string[10] dynamic;[/color]

                    The above would lead to a compiler error.

                    This:

                    string[] dynamic = new string[10];

                    Would create a single dimensional array of string types.

                    --
                    Scott



                    On Sun, 5 Sep 2004 12:12:34 +0200, "Cor Ligthert"
                    <notfirstname@p lanet.nl> wrote:
                    [color=blue]
                    >Spare,
                    >
                    >You declare a "static" string as
                    >
                    >string[10] dynamic;
                    >
                    >A nice string with a fixed lenght with the name dynamic.
                    >
                    >For dynamic array typen check all the iList collections (from which is the
                    >fixex lenght array one)
                    >http://msdn.microsoft.com/library/de...classtopic.asp
                    >
                    >For even more have a look at the link iCollection on that bottom of that
                    >page
                    >
                    >I hope this helps?
                    >
                    >Cor
                    >[/color]

                    Comment

                    • Austin Ehlers

                      #11
                      Re: dynamic string[]

                      On Sun, 05 Sep 2004 03:43:53 GMT, "Spare Change"
                      <sparechange@sp am.spam> wrote:
                      [color=blue]
                      >I am told that I can have a dynamic or static string array.
                      >
                      >So if I declare
                      >
                      >string[] dynamic;
                      >
                      >How do I add elements to dynamic and resize it ?[/color]

                      using System.Collecti ons.Specialized ;

                      ....
                      StringCollectio n sc=new StringCollectio n();
                      sc.Add(str1);
                      ....
                      //get a real string[] when done if needed

                      int len=sc.Count;
                      string[] strings=new string[len];
                      sc.CopyTo(strin gs,0);

                      Austin Ehlers

                      Comment

                      • Cor Ligthert

                        #12
                        Re: dynamic string[]

                        Scott,

                        I should avoid writting C# code and not using the IDE.
                        (I write everything automaticly in a VBNet way)

                        :-)

                        Thanks,

                        Cor


                        Comment

                        • Cor Ligthert

                          #13
                          Re: dynamic string[]

                          >[color=blue]
                          > I see no evidence, that once declared, that a primitive string[] can be
                          > 'ReDim'ed
                          >[/color]

                          I hope I am not wrong in this way, however as far as I know are there some
                          differences between the Array and in C# and VBNet.

                          In VBNet there is the Redim, however I would only using that when converting
                          a program from VB6 to VBNet and even than check for it and replace when that
                          is in it directly for a more dynamic one as I showed in a previous message
                          in this thread.

                          Redim seems to be a very performance consuming instruction.

                          Just my thought,

                          Cor


                          Comment

                          • Paul Wardle

                            #14
                            Re: dynamic string[]

                            That is just mad!

                            "The Devil" <eldiablo@hadez .nyc.spamo> wrote in message
                            news:yAA_c.7884 $w%6.5737@newsr ead1.news.pas.e arthlink.net...[color=blue]
                            >
                            > I went with a resizing routine.
                            >
                            > foreach(Match m1 in mc1)
                            > {
                            > temp = new string[i+1];
                            > anchors.CopyTo( temp,0);
                            > temp[i++]=fileName+"#"+m 1.Value.Substri ng(5,m1.Length-5);
                            > anchors=temp;
                            > }
                            >
                            >
                            > Marijan Tadin wrote:
                            >[color=green]
                            > > Try Sytem.Text.Stri ngBuilder
                            > >
                            > > Marijan
                            > >
                            > >
                            > > "Spare Change" <sparechange@sp am.spam> wrote in message
                            > > news:ZXv_c.660$ ip2.326@newsrea d3.news.pas.ear thlink.net...[color=darkred]
                            > >> I am told that I can have a dynamic or static string array.
                            > >>
                            > >> So if I declare
                            > >>
                            > >> string[] dynamic;
                            > >>
                            > >> How do I add elements to dynamic and resize it ?
                            > >>
                            > >>
                            > >>
                            > >>
                            > >> ---
                            > >> Outgoing mail is certified Virus Free.
                            > >> Checked by AVG anti-virus system (http://www.grisoft.com).
                            > >> Version: 6.0.752 / Virus Database: 503 - Release Date: 9/3/2004
                            > >>
                            > >>[/color][/color]
                            >
                            > --
                            > incognito http://kentpsychedelic.blogspot.com
                            > new material added 9/5[/color]


                            Comment

                            • Jaroslaw Kowalski

                              #15
                              Re: dynamic string[]


                              System.Collecti ons.Specialized .StringCollecti on should do. The interface is
                              very similar to string[] (except that Length is changed to Count) and you
                              can do Add()/Remove().

                              Jarek

                              "Paul Wardle" <p.wardle@ntlwo rld.com> wrote in message
                              news:ue05K3DlEH A.3340@TK2MSFTN GP14.phx.gbl...[color=blue]
                              > That is just mad!
                              >
                              > "The Devil" <eldiablo@hadez .nyc.spamo> wrote in message
                              > news:yAA_c.7884 $w%6.5737@newsr ead1.news.pas.e arthlink.net...[color=green]
                              > >
                              > > I went with a resizing routine.
                              > >
                              > > foreach(Match m1 in mc1)
                              > > {
                              > > temp = new string[i+1];
                              > > anchors.CopyTo( temp,0);
                              > >[/color][/color]
                              temp[i++]=fileName+"#"+m 1.Value.Substri ng(5,m1.Length-5);[color=blue][color=green]
                              > > anchors=temp;
                              > > }
                              > >
                              > >
                              > > Marijan Tadin wrote:
                              > >[color=darkred]
                              > > > Try Sytem.Text.Stri ngBuilder
                              > > >
                              > > > Marijan
                              > > >
                              > > >
                              > > > "Spare Change" <sparechange@sp am.spam> wrote in message
                              > > > news:ZXv_c.660$ ip2.326@newsrea d3.news.pas.ear thlink.net...
                              > > >> I am told that I can have a dynamic or static string array.
                              > > >>
                              > > >> So if I declare
                              > > >>
                              > > >> string[] dynamic;
                              > > >>
                              > > >> How do I add elements to dynamic and resize it ?
                              > > >>
                              > > >>
                              > > >>
                              > > >>
                              > > >> ---
                              > > >> Outgoing mail is certified Virus Free.
                              > > >> Checked by AVG anti-virus system (http://www.grisoft.com).
                              > > >> Version: 6.0.752 / Virus Database: 503 - Release Date: 9/3/2004
                              > > >>
                              > > >>[/color]
                              > >
                              > > --
                              > > incognito http://kentpsychedelic.blogspot.com
                              > > new material added 9/5[/color]
                              >
                              >[/color]


                              Comment

                              Working...