To ensure optimal performance, prefer the first two when you plan to delete multiple contiguous elements instead of repeatedly calling s. In other words, use member functions that operate on ranges instead of single elements—especially for those member functions that modify the contents of the string or sequence.
By doing so, you will avoid the extra function calls to erase for each element in the sequence, and you will permit the string implementation to more intelligently manage its data. Skip to main content. Start your free trial. Removing a Substring from a String. Example Improve this answer. You may decrease the number of strlen calls by caching str length, decreasing it each time the sub has been removed — Netherwire.
Netherwire: Good point, but it makes the code more cumbersome, especially if one wants to avoid computing strlen str if there is no match. Thanks for teasing me I found an even better solution : — chqrlie. There might be other bugs, can you be more specific and tell me what arguments are causing the segfault? Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name.
Email Required, but never shown. The Overflow Blog. Podcast Helping communities build their own LTE networks. Podcast Making Agile work for data science. Your email address will not be published. This site uses Akismet to reduce spam. Learn how your comment data is processed. Related Posts. Leave a Comment Cancel Reply Your email address will not be published.
0コメント