scanning a string for the third "part"...

 

Hi,

I have a string in which "<row>" and "</row>" is insert 5 times.

Now I want to extract the parts between

the first "<row>" and "</row>" into string1

the second "<row>" and "</row>"into string2

the third "<row>" and "</row>"into string3

....

I tried it like that (but that way I am only getting the first and the second string and in string3 +string4 +string5 is the second string, too!)

I can understand that, because I had to say, that I want to find the third, fourth, five... <row>... but how??

   for(zaehler = 0; zaehler < maxOpenOrders; zaehler++)
   {
      pos_start = StringFind(buffer_read,"<row>",pos_end);
      pos_end = StringFind(buffer_read,"</row>",pos_end);
      Row[zaehler] = StringSubstr(buffer_read,pos_start+5,pos_end-pos_start-5);
      Print("Row["+zaehler+"=", Row[zaehler]);
   }

 
sunshineh:

Hi,

I have a string in which "<row>" and "</row>" is insert 5 times.

Now I want to extract the parts between

the first "<row>" and "</row>" into string1

the second "<row>" and "</row>"into string2

the third "<row>" and "</row>"into string3

....

I tried it like that (but that way I am only getting the first and the second string and in string3 +string4 +string5 is the second string, too!)

I can understand that, because I had to say, that I want to find the third, fourth, five... <row>... but how??

Hi sunshineh.

This is a script.

:D

int start()
  {
  string text, txt, 
  sheep_row ="<row>one sheep<\row><row>two sheep<\row><row>three sheep<\row><row>four sheep<\row><row>five sheep<\row>";
  
  int pos, one, two, start = 0, lenght_0 = StringLen (sheep_row), lenght_1;
  
  for ( pos = start; pos < lenght_0; pos = start)
   {
    one = StringFind (sheep_row, "<row>", start);
    two = StringFind (sheep_row, "<\row>", start);
    
    lenght_1 = one + StringLen ("<row>");
    text = StringSubstr (sheep_row, lenght_1, two - lenght_1);
    start = two + StringLen ("<\row>");
    txt = txt+ " "+ text;
    Alert (txt);
    }
  
   PlaySound("wait.wav");
   return(0);
  }
 
pos_end=0;
  for(zaehler = 0; zaehler < maxOpenOrders; zaehler++)
   {
      pos_start = StringFind(buffer_read,"<row>",pos_end);
      pos_end = StringFind(buffer_read,"</row>",pos_start);// pos_end);
      Row[zaehler] = StringSubstr(buffer_read,pos_start+5,pos_end-pos_start-5);
      Print("Row["+zaehler+"=", Row[zaehler]);
   }
 
Thank you, it works!
 

Hi sunshineh,

:D

  string text,
  sheep_row ="<row>one sheep<\row><row>two sheep<\row><row>three sheep<\row><row>four sheep<\row><row>five sheep<\row>";
  
  int pos, one, two, start = 0, lenght_0 = StringLen (sheep_row);
  
  for ( pos = start; pos < lenght_0; pos = start)
   {
    one = StringFind (sheep_row, ">", start) + 1;
    two = StringFind (sheep_row, "<", one);
    if (one < two) 
      {
      text = StringSubstr (sheep_row, one , two - one);
      start = two; 
      }
      else
      { 
      text = "";
      start = one;
      }
    if (text != "") Alert (text);
    }
Reason: