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. doubt in cstring..

doubt in cstring..

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
8 Posts 4 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
    Rakesh5
    wrote on last edited by
    #1

    hi i have a basic doubt in cstring.. i have like this: CString test = hello; #define abc L"hello" if (test.find(CString(abc)) == 0) ------ ----- But this if condition is failing...May i know the reason? how to make it to pass??? Can anyone enlighten me about this issue? Thanks, rakesh.

    D S 2 Replies Last reply
    0
    • R Rakesh5

      hi i have a basic doubt in cstring.. i have like this: CString test = hello; #define abc L"hello" if (test.find(CString(abc)) == 0) ------ ----- But this if condition is failing...May i know the reason? how to make it to pass??? Can anyone enlighten me about this issue? Thanks, rakesh.

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

      Rakesh5 wrote:

      CString test = hello;

      What is hello? Is it a string literal or an undeclared variable?

      Rakesh5 wrote:

      if (test.find(CString(abc)) == 0)

      find() is not a member of CString. Perhaps you meant Find(). Why the extraneous CString construct? All that aside, your code snippet works for me.

      "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

      R 1 Reply Last reply
      0
      • D David Crow

        Rakesh5 wrote:

        CString test = hello;

        What is hello? Is it a string literal or an undeclared variable?

        Rakesh5 wrote:

        if (test.find(CString(abc)) == 0)

        find() is not a member of CString. Perhaps you meant Find(). Why the extraneous CString construct? All that aside, your code snippet works for me.

        "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

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

        Hi David, hello is just a string literal (for example purpose..) and I meant Find only... my doubt is : CString str(test); CString str1 = L"test"; Are str and str1 same?? if not, how to make it same?? thanks, rakesh.

        D 1 Reply Last reply
        0
        • R Rakesh5

          Hi David, hello is just a string literal (for example purpose..) and I meant Find only... my doubt is : CString str(test); CString str1 = L"test"; Are str and str1 same?? if not, how to make it same?? thanks, rakesh.

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

          Rakesh5 wrote:

          Are str and str1 same??

          No, they are two separate objects. How would that differ from:

          int x = 5;
          int y = 5;

          Are x and y the same?

          Rakesh5 wrote:

          if not, how to make it same??

          You can't, but you can make them contain the same value.

          "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

          R 1 Reply Last reply
          0
          • D David Crow

            Rakesh5 wrote:

            Are str and str1 same??

            No, they are two separate objects. How would that differ from:

            int x = 5;
            int y = 5;

            Are x and y the same?

            Rakesh5 wrote:

            if not, how to make it same??

            You can't, but you can make them contain the same value.

            "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

            R Offline
            R Offline
            Rakesh5
            wrote on last edited by
            #5

            Hi David, i think am not communicating properly.. see, my code has like this: CString str = "hello"; #define test L"hello"; if(str.Find(CString(test)) == 0) { -------- ------ } but its not passing this "if" statement.. my doubt is both are having hello only.. but y "if" condition is failing?? Thanks, rakesh

            D M 2 Replies Last reply
            0
            • R Rakesh5

              Hi David, i think am not communicating properly.. see, my code has like this: CString str = "hello"; #define test L"hello"; if(str.Find(CString(test)) == 0) { -------- ------ } but its not passing this "if" statement.. my doubt is both are having hello only.. but y "if" condition is failing?? Thanks, rakesh

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

              Rakesh5 wrote:

              but its not passing this "if" statement..

              Have you stepped into it using the debugger, or are you just looking at the ----- statements to know if the code is correct?

              "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
              • R Rakesh5

                hi i have a basic doubt in cstring.. i have like this: CString test = hello; #define abc L"hello" if (test.find(CString(abc)) == 0) ------ ----- But this if condition is failing...May i know the reason? how to make it to pass??? Can anyone enlighten me about this issue? Thanks, rakesh.

                S Offline
                S Offline
                SilimSayo
                wrote on last edited by
                #7

                Try the String.CompareTo method.

                1 Reply Last reply
                0
                • R Rakesh5

                  Hi David, i think am not communicating properly.. see, my code has like this: CString str = "hello"; #define test L"hello"; if(str.Find(CString(test)) == 0) { -------- ------ } but its not passing this "if" statement.. my doubt is both are having hello only.. but y "if" condition is failing?? Thanks, rakesh

                  M Offline
                  M Offline
                  MsmVc
                  wrote on last edited by
                  #8

                  i hope it's help you [code] CString test = "hello"; CString test=CString(abc); if (test.Find(test) == 0) { } [/code]

                  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