4 Replies - 21308 Views - Last Post: 24 May 2011 - 02:01 PM Rate Topic: -----

#1 and1dre  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 69
  • Joined: 30-March 09

Fastest way to remove a substring from a string

Posted 22 May 2011 - 08:51 PM

Hello all,

I was wondering if you guys could suggest the fastest/efficient way of removing a substring from a string.
For example, if this is my string,

The name is James Bond and I want to remove name is
what would be the best way of doing this?

Thx :)

Is This A Good Question/Topic? 0
  • +

Replies To: Fastest way to remove a substring from a string

#2 ishkabible  Icon User is offline

  • spelling expret
  • member icon





Reputation: 1739
  • View blog
  • Posts: 5,895
  • Joined: 03-August 09

Re: Fastest way to remove a substring from a string

Posted 22 May 2011 - 08:55 PM

std::string::substr

there are other algorithms that you can find online(Google string searching algorithms), however it would be very difficult to implement something faster than than the standard library.
Was This Post Helpful? 0
  • +
  • -

#3 and1dre  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 69
  • Joined: 30-March 09

Re: Fastest way to remove a substring from a string

Posted 22 May 2011 - 08:57 PM

I'll check that out. Thx for the tip!
Was This Post Helpful? 0
  • +
  • -

#4 Bench  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 944
  • View blog
  • Posts: 2,464
  • Joined: 20-August 07

Re: Fastest way to remove a substring from a string

Posted 24 May 2011 - 01:54 PM

I think std::string::replace would be easier. You could find "name is " and replace it with an empty string ""


Example here:
http://www.devx.com/.../16972/0/page/3

This post has been edited by Bench: 24 May 2011 - 01:55 PM

Was This Post Helpful? 0
  • +
  • -

#5 jimblumberg  Icon User is offline

  • member icon

Reputation: 5332
  • View blog
  • Posts: 16,601
  • Joined: 25-December 09

Re: Fastest way to remove a substring from a string

Posted 24 May 2011 - 02:01 PM

You could also use std::string erase().

Jim
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1