Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CString count

CString count

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
11 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rdop
    wrote on last edited by
    #1

    Hi All How can i ReversFind and count number of words?I have CString name="agsdfgggggg" how can count and cut these part "gggggg" from name. I mean i want to show this CString name="agsdfgggggg" to CString name="agsdf". Can any one help me.

    M C L C _ 5 Replies Last reply
    0
    • R rdop

      Hi All How can i ReversFind and count number of words?I have CString name="agsdfgggggg" how can count and cut these part "gggggg" from name. I mean i want to show this CString name="agsdfgggggg" to CString name="agsdf". Can any one help me.

      M Offline
      M Offline
      Michael Schubert
      wrote on last edited by
      #2

      Is "agsdfgggggg" a unique string? Is there some pattern? Does it always have the same number of characters? If you give us a bit more information we may be able to give you better advice than CString::Left(6) for example.

      R 1 Reply Last reply
      0
      • M Michael Schubert

        Is "agsdfgggggg" a unique string? Is there some pattern? Does it always have the same number of characters? If you give us a bit more information we may be able to give you better advice than CString::Left(6) for example.

        R Offline
        R Offline
        rdop
        wrote on last edited by
        #3

        how to count number 6?

        C 1 Reply Last reply
        0
        • R rdop

          Hi All How can i ReversFind and count number of words?I have CString name="agsdfgggggg" how can count and cut these part "gggggg" from name. I mean i want to show this CString name="agsdfgggggg" to CString name="agsdf". Can any one help me.

          C Offline
          C Offline
          Cedric Moonen
          wrote on last edited by
          #4

          Wow, I have no clue what you are talking about but the answer is probably liquid nitrogen[^] Ok, serriously now. What does ReverseFind have to do with your question ? Why are you talking about words (I only see letters in your string) ? Is your string always "agsdfgggggg" and you always need to remove "gggggg" ? In which case, I don't see why you are asking the question :doh:

          Cédric Moonen Software developer
          Charting control [v2.0] OpenGL game tutorial in C++

          D 1 Reply Last reply
          0
          • R rdop

            how to count number 6?

            C Offline
            C Offline
            Cedric Moonen
            wrote on last edited by
            #5

            1 2 3 4 5 6 Sorry, couldn't resist... :-D

            Cédric Moonen Software developer
            Charting control [v2.0] OpenGL game tutorial in C++

            M 1 Reply Last reply
            0
            • R rdop

              Hi All How can i ReversFind and count number of words?I have CString name="agsdfgggggg" how can count and cut these part "gggggg" from name. I mean i want to show this CString name="agsdfgggggg" to CString name="agsdf". Can any one help me.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Take a look at the MSDN pages for CString(). This class contains many useful functions, one of which will probably solve your problem.

              1 Reply Last reply
              0
              • C Cedric Moonen

                1 2 3 4 5 6 Sorry, couldn't resist... :-D

                Cédric Moonen Software developer
                Charting control [v2.0] OpenGL game tutorial in C++

                M Offline
                M Offline
                Michael Schubert
                wrote on last edited by
                #7

                I don't blame you. :-D

                1 Reply Last reply
                0
                • R rdop

                  Hi All How can i ReversFind and count number of words?I have CString name="agsdfgggggg" how can count and cut these part "gggggg" from name. I mean i want to show this CString name="agsdfgggggg" to CString name="agsdf". Can any one help me.

                  C Offline
                  C Offline
                  CPallini
                  wrote on last edited by
                  #8

                  What about

                  CString name = "agsdfgggggg";
                  int l = name.GetLength();

                  int count=0;

                  while (l-- > 0)
                  {
                  if ( name[l] != 'g') break;
                  count++;
                  }

                  if ( count > 0 )
                  {
                  name = name.Left(name.GetLength() - count);
                  }

                  ? [added] Sorry for the poor answer, I didn't realize that correct one is LIQUID NITROGEN. [/added] :)

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                  [My articles]

                  R 1 Reply Last reply
                  0
                  • C CPallini

                    What about

                    CString name = "agsdfgggggg";
                    int l = name.GetLength();

                    int count=0;

                    while (l-- > 0)
                    {
                    if ( name[l] != 'g') break;
                    count++;
                    }

                    if ( count > 0 )
                    {
                    name = name.Left(name.GetLength() - count);
                    }

                    ? [added] Sorry for the poor answer, I didn't realize that correct one is LIQUID NITROGEN. [/added] :)

                    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                    [My articles]

                    R Offline
                    R Offline
                    rdop
                    wrote on last edited by
                    #9

                    Thanks for responce.

                    1 Reply Last reply
                    0
                    • R rdop

                      Hi All How can i ReversFind and count number of words?I have CString name="agsdfgggggg" how can count and cut these part "gggggg" from name. I mean i want to show this CString name="agsdfgggggg" to CString name="agsdf". Can any one help me.

                      _ Offline
                      _ Offline
                      _Superman_
                      wrote on last edited by
                      #10

                      Let me restate your requirement. You want the repeating character at the end to be removed. If this requirement is correct, here is what you can do. name = name.TrimRight(name[name.GetLength() - 1]); Of course, you will need error checking, which I have omitted.

                      «_Superman_» I love work. It gives me something to do between weekends.

                      1 Reply Last reply
                      0
                      • C Cedric Moonen

                        Wow, I have no clue what you are talking about but the answer is probably liquid nitrogen[^] Ok, serriously now. What does ReverseFind have to do with your question ? Why are you talking about words (I only see letters in your string) ? Is your string always "agsdfgggggg" and you always need to remove "gggggg" ? In which case, I don't see why you are asking the question :doh:

                        Cédric Moonen Software developer
                        Charting control [v2.0] OpenGL game tutorial in C++

                        D Offline
                        D Offline
                        David Crow
                        wrote on last edited by
                        #11

                        Cedric Moonen wrote:

                        Is your string always "agsdfgggggg" and you always need to remove "gggggg" ? In which case, I don't see why you are asking the question

                        Have you ever tried to use agsdf when it was next to gggggg? It's difficult at best.

                        "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups