parsing the value in between two XML tags

前端 未结 1 2002
孤街浪徒
孤街浪徒 2021-01-24 18:04

I know this one has been asked before, however I can\'t seem to find a suitable solution, so I \'ll state the problem:

I have a string of characters that is similar to a

1条回答
  •  太阳男子
    2021-01-24 18:32

    I would just use strstr():

    char * get_value(const char *input)
    {
      const char *start, *end;
    
      if((start = strstr(input, "")) != NULL)
      {
        start += strlen("");
        if((end = strstr(start, "")) != NULL)
        {
          char *out = malloc(end - start + 1);
          if(out != NULL)
          {
            memcpy(out, start, (end - start));
            out[end - start] = '\0';
            return out;
          }
        }
      }
      return NULL;
    }
    

    Note that the above is untested, written directly into the SO edit box. So, it's almost guaranteed to contain at least one off-by-one error.

    0 讨论(0)
提交回复
热议问题