Thread: Substring a CString

  1. #1
    Android geek@02's Avatar
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    470

    Substring a CString

    Hi.
    CString class doesn’t have a substr method. What's the easiest way to substring a CString string? (say, to retrieve 5th to 20th chars of a CString).
    THX.
    GameJolt: https://gamejolt.com/@KasunL
    Game Development Youtube:
    https://is.gd/XyhYoP
    Amateur IT Blog: http://everything-geeky.blogspot.com/



    (and, sorry for my amateur English)

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Use the "Mid" member function.

    --
    Mats

  3. #3
    Android geek@02's Avatar
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    470
    Thanx mats.
    Could u please help me a little bit with this too?: Now, i have to read a html file and extract the links within it. if the user say to retreve all links that points to .zip files, i have to retrieve only those links. so what i'm trying to do is to search for the extention (.zip) 1st, then reverse find that link's (assuming that it's a link) head(http) from there. what do u think the easyest way to reverse find the link head?
    THX again.
    Last edited by geek@02; 08-17-2007 at 07:21 AM.
    GameJolt: https://gamejolt.com/@KasunL
    Game Development Youtube:
    https://is.gd/XyhYoP
    Amateur IT Blog: http://everything-geeky.blogspot.com/



    (and, sorry for my amateur English)

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Hmm. That doesn't sound very trivial to me. I would probably start by scanning for "<a" and "</a>" in pairs, then look inside what I found from that.

    Of course, if you have the whole HTML page as one long string, there are other ways to do it, but searching backwards can have some problems. And beware that I may type "foo.zip" in my web-page without actually the page containing a link to any .zip file at all, so you need to figure out if it's inside a link-tag sooner or later anyways.

    --
    Mats

  5. #5
    Android geek@02's Avatar
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    470
    yeah u r right. this reverse-find thing is messy. appriciate your sugesstion about scanning <a tags. thx.
    GameJolt: https://gamejolt.com/@KasunL
    Game Development Youtube:
    https://is.gd/XyhYoP
    Amateur IT Blog: http://everything-geeky.blogspot.com/



    (and, sorry for my amateur English)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inserting a swf file in a windows application
    By face_master in forum Windows Programming
    Replies: 12
    Last Post: 05-03-2009, 11:29 AM
  2. Writing CObjects with Serialization to CArchive
    By ruben_gerad in forum C++ Programming
    Replies: 0
    Last Post: 11-09-2006, 08:25 AM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. Help with CString class and operator+ overloading
    By skanxalot in forum C++ Programming
    Replies: 2
    Last Post: 10-07-2003, 10:23 AM
  5. CString Objects & subString :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 06-19-2002, 07:40 AM