DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: exact string matching and replace

  1. #1
    Join Date
    Apr 2011
    Posts
    13

    exact string matching and replace

    Hello could anyone please help me find any combination of date i-e "yyyymmdd" within a '/' separated string e-g
    Code:
    string = "str1/str2/yyyymmdd/stryymm/str3/str4/str5_yymmdd.b/yyyymm_000.a"
    and replace it with an actual date e-g
    Code:
    string date = "20110520"
    and then
    Code:
    stryymm would become str1105
    yyyymmdd = 20110520
    str5_yymmdd.b = str5_110520.b
    yyyymm_000.a = 201105_000.a
    Thanks

  2. #2
    Join Date
    Dec 2007
    Posts
    401
    Code:
    std::string& replace_all_substrings( std::string& str, const std::string& original,
                                         const std::string& replacement )
    {
        typedef std::string::size_type pos_t ;
        std::string str_replaced ;
        pos_t orig_len = original.size() ;
    
        for( pos_t pos = str.find(original) ; pos != std::string::npos ; pos = str.find(original) )
        {
            str_replaced += str.substr( 0, pos ) + replacement ;
            str = str.substr(pos+orig_len) ;
        }
        return str = str_replaced + str ;
    }

  3. #3
    Join Date
    Apr 2011
    Posts
    13
    Is there anyway I can keep a check on:

    if the third and fourth y's i-e the 'year' part of the date does not exist then the centuary part i-e first and second y's must also not be replaced with the actual centuary part of the date. We can call the centuary part as 'cc'. Like wise if 'mm' part i-e month does not exist then 'dd' i-e day part must also not be replaced. Also more than two or less two cc's or yy's or mm's or dd's must also be ignored or should display a msg for example that date is incorrect.

    Thanks in advance
    Last edited by vbaswant; 05-24-2011 at 04:30 AM.

Similar Threads

  1. Remove trailing and leading whitespace?
    By chupacabra in forum VB Classic
    Replies: 12
    Last Post: 12-01-2006, 12:12 PM
  2. Replies: 0
    Last Post: 10-24-2002, 04:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center