Convert a string

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

    Convert a string

    Hello,
    I want to convert a string Array permanantly to a int Array.
    Everywhere in my code I have to use Convert.ToInt32 to use the data. I
    just want to change it once.
    Thanks
    Mike
  • Alberto Poblacion

    #2
    Re: Convert a string

    "AMP" <ampeloso@gmail .comwrote in message
    news:0ea11424-07af-45d7-b0d3-9946f1b7b851@u1 2g2000prd.googl egroups.com...
    I want to convert a string Array permanantly to a int Array.
    Everywhere in my code I have to use Convert.ToInt32 to use the data. I
    just want to change it once.
    The array cannot change types on the fly. You wil have to allocate a new
    int Array, convert all the strings from the string array into the int array,
    and then deallocate the string array. The simplest, although maybe not the
    prettiest way to write it, is a loop that converts each element:

    string[] theStrings = ...;
    int[] theInts new int[theStrings.Leng th];
    for (int i=0; i<theStrings.Le ngth; i++)
    theInts[i]=int.Parse(theS trings[i]);


    Comment

    • =?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=

      #3
      Re: Convert a string

      AMP wrote:
      Hello,
      I want to convert a string Array permanantly to a int Array.
      Everywhere in my code I have to use Convert.ToInt32 to use the data. I
      just want to change it once.
      Thanks
      Mike
      If you're storing integers in the array, why not just declare it as an
      int array?

      --
      Lasse Vågsæther Karlsen
      mailto:lasse@vk arlsen.no
      Blogger ist ein Veröffentlichungs-Tool von Google, mit dem du ganz einfach deine Gedanken der Welt mitteilen kannst. Mit Blogger kannst du problemlos Texte, Fotos und Videos in deinem persönlichen Blog oder deinem Team-Blog veröffentlichen.

      PGP KeyID: 0xBCDEA2E3

      Comment

      Working...