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. check the characters in a string

check the characters in a string

Scheduled Pinned Locked Moved C / C++ / MFC
question
11 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.
  • A Anu_Bala

    Hi, my string is CString STemp="PV SV MD"; I have to check whether SV or PV or MD is present in the string. if(PV is present) { certain functions; } if(SV is present) { } I have to check the presence of any two characters in a string.How can i make this? I use Find() but it gives the position but i want a particular character. Any function is there??Pls...

    Anu

    P Offline
    P Offline
    prasad_som
    wrote on last edited by
    #2

    Anu_Bala wrote:

    I use Find() but it gives the position but i want a particular character.

    PV or SV you mentioned are strings.

    Anu_Bala wrote:

    I use Find() but it gives the position but i want a particular character

    Whats problem with this ? if Find return -1, string is not present, other wise its there.

    Prasad Notifier using ATL

    A 1 Reply Last reply
    0
    • A Anu_Bala

      Hi, my string is CString STemp="PV SV MD"; I have to check whether SV or PV or MD is present in the string. if(PV is present) { certain functions; } if(SV is present) { } I have to check the presence of any two characters in a string.How can i make this? I use Find() but it gives the position but i want a particular character. Any function is there??Pls...

      Anu

      V Offline
      V Offline
      velayudhan_raj
      wrote on last edited by
      #3

      Hi, You can use Strcmp function to compare two strings. Regards Velayudhan

      1 Reply Last reply
      0
      • A Anu_Bala

        Hi, my string is CString STemp="PV SV MD"; I have to check whether SV or PV or MD is present in the string. if(PV is present) { certain functions; } if(SV is present) { } I have to check the presence of any two characters in a string.How can i make this? I use Find() but it gives the position but i want a particular character. Any function is there??Pls...

        Anu

        H Offline
        H Offline
        Hamid Taebi
        wrote on last edited by
        #4

        use CString::Find if your string isnt exist return value of Find is -1 else its location of string

        _**


        **_

        WhiteSky


        1 Reply Last reply
        0
        • P prasad_som

          Anu_Bala wrote:

          I use Find() but it gives the position but i want a particular character.

          PV or SV you mentioned are strings.

          Anu_Bala wrote:

          I use Find() but it gives the position but i want a particular character

          Whats problem with this ? if Find return -1, string is not present, other wise its there.

          Prasad Notifier using ATL

          A Offline
          A Offline
          Anu_Bala
          wrote on last edited by
          #5

          Ya, i used Find(). I need one more help that is my string reads like this "pv m3 PV|| sv m3 SV||MD||" here i want to extract the string " sv m3 " from the above string.The number of characters may vary.But space and new line are used to seperate the words. Pls help me out. I think u get my point.

          Anu

          P 1 Reply Last reply
          0
          • A Anu_Bala

            Ya, i used Find(). I need one more help that is my string reads like this "pv m3 PV|| sv m3 SV||MD||" here i want to extract the string " sv m3 " from the above string.The number of characters may vary.But space and new line are used to seperate the words. Pls help me out. I think u get my point.

            Anu

            P Offline
            P Offline
            prasad_som
            wrote on last edited by
            #6

            Anu_Bala wrote:

            here i want to extract the string " sv m3 " from the above string

            Then whats problem with Find ?

            Anu_Bala wrote:

            The number of characters may vary

            I assume you want to say, it can "SV m3 SV",is it?,

            Prasad Notifier using ATL

            A 1 Reply Last reply
            0
            • P prasad_som

              Anu_Bala wrote:

              here i want to extract the string " sv m3 " from the above string

              Then whats problem with Find ?

              Anu_Bala wrote:

              The number of characters may vary

              I assume you want to say, it can "SV m3 SV",is it?,

              Prasad Notifier using ATL

              A Offline
              A Offline
              Anu_Bala
              wrote on last edited by
              #7

              Thanks for reply.. I explain you my need in details. First the string is like this sTemp="sub m3 PV||add m3 SV||MD||" Then i have to extract few things and i have to put in to seperate string Final String, CString StrFinal = "PV||SV||MD" I know to extract first two things i.e., sub m3 i did like this int pos2 = sTemp.Find("\n"); sTemp3 = sTemp.Mid(pos2-3); sTemp=sTemp3; here STemp = PV||add m3 SV||MD And then i have to extract add and m3. But i dont know to extract the middle add m3 . i need this thing

              Anu

              P H 2 Replies Last reply
              0
              • A Anu_Bala

                Thanks for reply.. I explain you my need in details. First the string is like this sTemp="sub m3 PV||add m3 SV||MD||" Then i have to extract few things and i have to put in to seperate string Final String, CString StrFinal = "PV||SV||MD" I know to extract first two things i.e., sub m3 i did like this int pos2 = sTemp.Find("\n"); sTemp3 = sTemp.Mid(pos2-3); sTemp=sTemp3; here STemp = PV||add m3 SV||MD And then i have to extract add and m3. But i dont know to extract the middle add m3 . i need this thing

                Anu

                P Offline
                P Offline
                prasad_som
                wrote on last edited by
                #8

                Cant you use same logic? i.e. I assume each sub string you mentioned here is preceded by '\n'. And what does || stands for ? Is it a kind of separator ? If yes, you can use it,too. i.e. Find "||" and extarct 2 chararacters preceding it. Keep appending result string.

                Prasad Notifier using ATL

                1 Reply Last reply
                0
                • A Anu_Bala

                  Thanks for reply.. I explain you my need in details. First the string is like this sTemp="sub m3 PV||add m3 SV||MD||" Then i have to extract few things and i have to put in to seperate string Final String, CString StrFinal = "PV||SV||MD" I know to extract first two things i.e., sub m3 i did like this int pos2 = sTemp.Find("\n"); sTemp3 = sTemp.Mid(pos2-3); sTemp=sTemp3; here STemp = PV||add m3 SV||MD And then i have to extract add and m3. But i dont know to extract the middle add m3 . i need this thing

                  Anu

                  H Offline
                  H Offline
                  Hamid Taebi
                  wrote on last edited by
                  #9

                  Do you need to get a middle a string like your example?

                  _**


                  **_

                  WhiteSky


                  A 1 Reply Last reply
                  0
                  • H Hamid Taebi

                    Do you need to get a middle a string like your example?

                    _**


                    **_

                    WhiteSky


                    A Offline
                    A Offline
                    Anu_Bala
                    wrote on last edited by
                    #10

                    Yes,that || is a newline character which is displayed like this in our coding.

                    Anu

                    H 1 Reply Last reply
                    0
                    • A Anu_Bala

                      Yes,that || is a newline character which is displayed like this in our coding.

                      Anu

                      H Offline
                      H Offline
                      Hamid Taebi
                      wrote on last edited by
                      #11

                      Is it possible for you to find space between add m3 or you dont have a space in your string

                      _**


                      **_

                      WhiteSky


                      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