Re: [Vala] How should an array be dynamically allocated?



Hello
Dynamiically allocated arrays are declared with 'string[] name'.
You should try this code:

int main() {
  string str = "I am#*- a exa#*-mple string c#*-ontaini#*-ng
non#*-sense";
  string[] sa = str.split("#*-");
  foreach(string s in sa)
    print("%s\n", s);
  return 0;
}




     void    str2bib(string str)
     {    int    i    =    count(str, @"$gs");
         string    sflds[]    =    new    string [i];
         sflds    =    str.split(@"$gs");
     }
/**    returns the number of times delim occurs within str    */
int    count (string str, string delim)
{    int    i, res;
     for    (i = 0, res = 0;    i <= str.length - delim.length;    i
++)
     {    if    (str[i: i + delim.length] == delim)    res++;    }
     return    res;
}






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]