Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7563457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:40:16+00:00 2026-05-30T13:40:16+00:00

I have this function sentanceParse with a string input which returns a list. The

  • 0

I have this function sentanceParse with a string input which returns a list. The input might be something like “Hello my name is Anton. What’s your name?” and then the return value would be a list containing “Hello my name is Anton” and “What’s your name?”. However, this is not what happens. It seems as if the whitespaces in the sentences are treated like a separator and therefore the return is rather “Hello”, “my”, “name” etc instead of what I expected.

How would you propose I solve this?

As I am not a 100% sure the problem does not lie within my code, I will add that to the post as well:

Main:

list<string> mylist = sentanceParse(textCipher);
list<string>::iterator it;
for(it = mylist.begin(); it != mylist.end(); it++){
    textCipher = *it;
    cout << textCipher << endl; //This prints out the words separately instead of the entire sentances.

sentanceParse:

list<string> sentanceParse(string strParse){
    list<string> strList;
    int len = strParse.length();
    int pos = 0;
    int count = 0;
    for(int i = 0; i < len; i++){
        if(strParse.at(i) == '.' || strParse.at(i) == '!' || strParse.at(i) == '?'){
            if(i < strParse.length() - 1){
                while(i < strParse.length() - 1 && (strParse.at(i+1) == '.' || strParse.at(i+1) == '!' || strParse.at(i+1) == '?')){
                    if(strParse.at(i+1) == '?'){
                        strParse.replace(i, 1, "?");
                    }
                    strParse.erase(i+1, 1);
                    len -= 1;
                }
            }
            char strTemp[2000];
            int lenTemp = strParse.copy(strTemp, i - pos + 1, pos);
            strTemp[lenTemp] = '\0';
            std::string strAdd(strTemp);
            strList.push_back(strAdd);
            pos = i + 1;
            count ++;
        }
    }

    if(count == 0){
        strList.push_back(strParse);
    }

    return strList;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T13:40:18+00:00Added an answer on May 30, 2026 at 1:40 pm

    Your implementation of sentence parse is wrong, here is a simpler correct solution.

    std::list<std::string> sentence_parse(const std::string &str){
        std::string temp;
        std::list<std::string> t;
    
        for(int x=0; x<str.size();++x){
           if(str[x]=='.'||str[x]=='!'||str[x]=='?'){
               if(temp!="")t.push_back(temp);//Handle special case of input with
                                             //multiple punctuation Ex. Hi!!!!
               temp="";
           }else temp+=str[x];
        }
        return t;
    }
    

    EDIT:

    Here is a full example program using this function. Type some sentences in your console, press enter and it will spit the sentences out with a newline separating them instead of punctuation.

    #include <iostream>
    #include <string>
    #include <list>
    std::list<std::string> sentence_parse(const std::string &str){
        std::string temp;
        std::list<std::string> t;
    
        for(int x=0; x<str.size();++x){
            if(str[x]=='.'||str[x]=='!'||str[x]=='?'){
                if(temp!="")t.push_back(temp);//Handle special case of input with
                                              //multiple punctuation Ex. Hi!!!!
                temp="";
            }else temp+=str[x];
        }
        return t;
    }
    int main (int argc, const char * argv[])
    {
        std::string s;
    
        while (std::getline(std::cin,s)) {       
            std::list<std::string> t= sentence_parse(s);
            std::list<std::string>::iterator x=t.begin();
            while (x!=t.end()) {
                 std::cout<<*x<<"\n";
                ++x;
            }
    
        }
    
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this function which generates a seo friendly url from a string :
I have this function... private string dateConvert(string datDate) { System.Globalization.CultureInfo cultEnGb = new System.Globalization.CultureInfo(en-GB);
I have this function: RegisterGlobalHotKey(Keys.F6, MOD_SHIFT | MOD_CONTROL); which call an API to register
I have this function which is supposed to open up a child window using
I have this function to unlock a list the user is currently editing: function
I have this function that shows a list of messages in reverse order. protected
I have this function public DataSet Fetch(string EntityName, ObjectParameter[] parameters, int pagesize, int pageindex)
I have this function: short cmd_Draw2DPoly(short ThreeDmode, sds_point startpoint[]){...} and I call it like
I have this function: public static void Play(string FileName, bool Async = false) {
I have this: function foo($a='apple', $b='brown', $c='Capulet') { // do something } Is something

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.