mardi 28 juin 2016

C++ Builder - Copy a Link to a String Based On Certain Words in It

This's my first post here.

I have 4 links in a Memo or TStringList:

http://website.com/text/book&id=20/programming
http://website.com/text/book&id=10/programming
http://website.com/text/book&id=40/programming
http://website.com/text/book&id=30/programming

What I want to do is to copy each link based on its "id number", as shown above to separate string, and NOT based on its index in TMemo or in TStringList.

This's because the id number of each link is always change every time or dynamics (it's a random id).

So let's say :

  1. if the link containts id=10 then it should be copied to a string called "id10".
    • final result is id10 containts: http://website.com/text/book&id=10/programming
  2. if the link containts id=30 then it should be copied to a string called "id30".
    • final result is id30 containts: http://website.com/text/book&id=30/programming
  3. so on and on until all links are copied into a separate different string.

I've tried to resolve this problem using substring function, such as:

int p = 0;
String id10, id20, id30, id40;
p = Memo1->Lines->Text.Pos("id=20");
if (p != 0)
{
  id10 = Memo1->Lines->Text.SubString(p + 1, Memo1->Lines->Text.Length());
  ShowMessage(id10);
}

......

Unfortunately, its always failed. Because I am new to c++ and the sort but I don't know what to do with all of it. I am sorry.

So I need your help to handle this situation.

Thank you very much.

Aucun commentaire:

Enregistrer un commentaire