Results 1 to 2 of 2

Thread: Question:How to reduce the spaces between words.

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    1

    Question:How to reduce the spaces between words.

    I want to know how to reduce the spaces between words if they are separated by more than one spaces.
    I know a little bit of it.After Scanning the string to see if a space is encountered,what am i supposed to do?

  2. #2
    Fanatic Member twanvl's Avatar
    Join Date
    Dec 2001
    Posts
    771

    Re: Question:How to reduce the spaces between words.

    You could use something like (pseudocode):
    Code:
    bool last_character_was_a_space = false;
    for-each-character {
       if char == space {
          if last_character_was_a_space {
             remove_character;
          } else {
             keep_character;
             last_character_was_a_space = true;
          }
       } else {
          keep_character;
          last_character_was_a_space = false;
       }
    }
    The simplest way to handle the removing is to just append the characters you want to keep to a new string:
    Code:
    std::string result;
      ...
        //keep_character
        result += char;

Posting Permissions

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



Click Here to Expand Forum to Full Width