RWCString


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: RWCString

Hybrid View

  1. #1
    Join Date
    May 2004
    Posts
    242

    RWCString

    Hello everyone,

    I have a RWCString which is ".../.../..../..../..." etc.

    Is there a way to remove all the forward slashes with nothing ? I found methods first and last which return the index of the location, but then I need to loop through the RWCString.

    I was hoping to do a pattern match and just remove all the flrward slashes in one go.

    Any ideas please ?

    Thanks,

    Ami.

  2. #2
    Join Date
    Dec 2003
    Posts
    3,366
    not sure what that string type is, but sprintf it into a char array and loop over *that* and poke it back into the string type when done. Many string classes prevent raw manipulation of their internal data, often because they maintain a "length" field that would become broken if you did this, so they simply don't allow it or make it extremely difficult. When you just can't find the workaround, the char array always works.

  3. #3
    Join Date
    Dec 2007
    Posts
    401
    if the string contains only single byte characters, there are two options:
    if portability of your code to non-roguewave implementations is not an issue, just do a regular expression pattern match and replacement. (note: this is easy, but not very efficient).
    Code:
    RWCString rwcstr( "abc/defgh/ijkl/mnopqr/st/uvwxyz" ) ;
    rwcstr.replace( RWCRExpr( "/" ), "", all ) ;
    if portability is desirable, use std::stable_partition to move all the '/' characters to the end of the string and then truncate the string. for example:
    Code:
    #include <string>
    #include <iostream>
    #include <algorithm>
    #include <functional>
    
    int main()
    {
       using namespace std ;
       string str = "abc/defgh/ijkl/mnopqr/st/uvwxyz" ;
       cout << str << '\n' ;
       str.erase( stable_partition( str.begin(), str.end(), bind2nd( not_equal_to<char>(), '/' ) ),
                        str.end() ) ;
       cout << str << '\n' ;
    }
    If your roguewave library build is based on the standard C++ library (this is the default), RWCString is just a wrapper over std::string. In this case, you can directly manipulate the underlying std::string object on which the RWCString is based.
    Code:
    RWCString rwcstr( "abc/defgh/ijkl/mnopqr/st/uvwxyz" ) ;
    std::string& str = rwcstr.std() ;
    str.erase( stable_partition( str.begin(), str.end(), bind2nd( not_equal_to<char>(), '/' ) ),
                     str.end() ) ;

Similar Threads

  1. Factory pattern
    By ami in forum C++
    Replies: 7
    Last Post: 09-01-2009, 09:19 PM

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