dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Returning an Empty String

  1. #1
    Join Date
    Aug 2019
    Posts
    6

    Returning an Empty String

    I am creating my own get first word and get last word functions for a project and I am able to return those certain words but my teacher wants us to return an empty string if the string entered doesn't have any words.

    Is there a way for me to create an if statement to check if the string has words?
    Something like:

    Code:
    if (string has no words)          // I just don't know what code to write to check for words, or would you check for isalpha and a space?
         return " "
    else if (string has words)
         return (either first or last word)
    any help would be greats, Thanks.
    Last edited by 2kaud; August 4th, 2019 at 04:53 AM. Reason: Added code tags

  2. #2
    Arjay's Avatar
    Arjay is online now Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,033

    Re: Returning an Empty String

    Are you a able to use the std:string class?

  3. #3
    Join Date
    Aug 2019
    Posts
    6

    Re: Returning an Empty String

    I think I am able to, but not completely sure.

  4. #4
    Arjay's Avatar
    Arjay is online now Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,033

    Re: Returning an Empty String

    Quote Originally Posted by UnknownHabits View Post
    I think I am able to, but not completely sure.
    Find out and then look online for "std string msdn". This will give you the documentation for the std string class in msdn which will describe its properties and methods. The split method will allow you to split up a string into a array of sub strings. In your case, you can split the sentence by the space character and get back an array of words.

    I've been told that there is no split method in std string. Instead try https://stackoverflow.com/questions/...ing-tokens-e-g
    Last edited by Arjay; August 5th, 2019 at 02:44 AM.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)