how to get the first word from line or any char array?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vj6940
    New Member
    • Oct 2008
    • 2

    how to get the first word from line or any char array?

    hi,
    i am writing a program to search first word from a line
    but i am not getting an idea to how to do this?
    if any one have a solution then mail me <Removed>

    thanks !!!!!
    Last edited by r035198x; Oct 24 '08, 06:37 AM. Reason: posting emails is against site rules
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    We don't give out boiler plate codes here.
    Read the posting guidelines to find out how to ask your questions.

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by vj6940
      hi,
      i am writing a program to search first word from a line
      but i am not getting an idea to how to do this?
      if any one have a solution then mail me <Removed>

      thanks !!!!!
      You write here, you read here. First you have to define what a 'word' is. Is an
      acronym a word? What about those dots? Or any punctuation character?

      kind regards,

      Jos

      Comment

      • Man4ish
        New Member
        • Mar 2008
        • 151

        #4
        words are generally separated by space, tab or delimiter. First find the position of first delimiter and then get the substring starting from 0 to that position.

        Manish

        Comment

        • compman9902
          New Member
          • Mar 2007
          • 105

          #5
          This is actually fairly simple, but as the Administrator said, we don't give that code out (using google and the terms that we give you it should be very simple). First of all, I am going to assume that you are using an std::string. Heres what you do:
          1) Find the first instance of the character "space" (yourString.fin d(" "))
          2) Take the substring of that from character 0 to whenever the space is using substr (yourString.sub str(0,yourStrin g.find(" "))

          Comment

          Working...