+ Reply to Thread
Results 1 to 2 of 2

Thread: Remove comma from a string

  1. #1
    Surfer is offline Senior Member
    Join Date
    Mar 2010
    Posts
    321

    Remove comma from a string

    You have a string which stores a number with commas. For example, a string that has the number 345,000,000. How will you manipulate this string in-place [without using any extra memory] so that the output is the original string without any commas in O(n) ?

  2. #2
    JavaGuy Guest
    Code:
    int nLen = strlen(str);
    char* pWriteTo = str;
    char* pReadFrom = str;
    for (int i = 0; i < nLen; i++)
    {
      if (*pReadFrom != ',')
      {
        *pWriteTo = *pReadFrom;
        pWriteTo++;
      }
      pReadFrom++;
    }

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Remove one comparison from Binary search
    By TopGun in forum Adobe
    Replies: 1
    Last Post: 7th August 2008, 20:53
  2. Remove chars
    By TopGun in forum Algorithm/Data Structure Questions
    Replies: 1
    Last Post: 17th June 2008, 11:30

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts