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. Problem with AfxFormatStrings

Problem with AfxFormatStrings

Scheduled Pinned Locked Moved C / C++ / MFC
helplearning
4 Posts 2 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.
  • U Offline
    U Offline
    uday kiran janaswamy
    wrote on last edited by
    #1

    Hi all, i am facing problem with AfxFormatString, as the the Parameters it will take from only "%1 to %9" as Arguments for subtitution from Resource String. Please help me to Append beyond that, I Mean after 9 th Parameter. code: ----- Resource String : String ID --------- IDS_GTD_WIZ_SET_STANDARD_CONTROLLER Caption ------- "It is necessary to set one or more equipment other than %1, %2,\n%3, %4, %5, %6, %7, %8,\n%9 and %10 to Communication ettings." Here i am trying to Subtitue this %1,%2,%3,%4,%5,%6,%7.... upto %9 but after subtituion of %10 i am not reflecting that. CString lC_Str_DriverArray[10]; UINT lui_Index = 0; lC_Str_DriverArray[lui_Index++].LoadString(IDS_GTD_WIZ_CONTROLLER_BARCODE); lC_Str_DriverArray[lui_Index++].LoadString(IDS_GTD_WIZARD_REFID); lC_Str_DriverArray[lui_Index++].LoadString(IDS_GTD_WIZ_CONTROLLER_GATEWAY); lC_Str_DriverArray[lui_Index++].LoadString(IDS_GTD_WIZ_CONTROLLER_ETHERNETDOWNLOAD); lC_Str_DriverArray[lui_Index++].LoadString(IDS_GTD_WIZ_CONTROLLER_PRINTER); lC_Str_DriverArray[lui_Index++].LoadString(IDS_GTD_WIZ_CONTROLLER_VIDEORGB); lC_Str_DriverArray[lui_Index++].LoadString(IDS_GTD_WIZ_CONTROLLER_RGBOUTPUT); //Extended Step Addition lC_Str_DriverArray[lui_Index++].LoadString(IDS_GTD_WIZ_EXTENDED_MEMORYCARD); lC_Str_DriverArray[lui_Index++].LoadString(IDS_GTD_WIZ_SOUND_OP_UNIT); lC_Str_DriverArray[lui_Index].LoadString(IDS_GTD_WIZ_EXTERNAL_IO_UNIT); //Load error message AfxFormatStrings(lC_Str_Msg,IDS_GTD_WIZ_SET_STANDARD_CONTROLLER,(LPCTSTR*)lC_Str_DriverArray,10); Here after 9th String i am getting Problem. in %10 it is subtituting as %1 what to do. please help me out.

    Uday kiran

    J 1 Reply Last reply
    0
    • U uday kiran janaswamy

      Hi all, i am facing problem with AfxFormatString, as the the Parameters it will take from only "%1 to %9" as Arguments for subtitution from Resource String. Please help me to Append beyond that, I Mean after 9 th Parameter. code: ----- Resource String : String ID --------- IDS_GTD_WIZ_SET_STANDARD_CONTROLLER Caption ------- "It is necessary to set one or more equipment other than %1, %2,\n%3, %4, %5, %6, %7, %8,\n%9 and %10 to Communication ettings." Here i am trying to Subtitue this %1,%2,%3,%4,%5,%6,%7.... upto %9 but after subtituion of %10 i am not reflecting that. CString lC_Str_DriverArray[10]; UINT lui_Index = 0; lC_Str_DriverArray[lui_Index++].LoadString(IDS_GTD_WIZ_CONTROLLER_BARCODE); lC_Str_DriverArray[lui_Index++].LoadString(IDS_GTD_WIZARD_REFID); lC_Str_DriverArray[lui_Index++].LoadString(IDS_GTD_WIZ_CONTROLLER_GATEWAY); lC_Str_DriverArray[lui_Index++].LoadString(IDS_GTD_WIZ_CONTROLLER_ETHERNETDOWNLOAD); lC_Str_DriverArray[lui_Index++].LoadString(IDS_GTD_WIZ_CONTROLLER_PRINTER); lC_Str_DriverArray[lui_Index++].LoadString(IDS_GTD_WIZ_CONTROLLER_VIDEORGB); lC_Str_DriverArray[lui_Index++].LoadString(IDS_GTD_WIZ_CONTROLLER_RGBOUTPUT); //Extended Step Addition lC_Str_DriverArray[lui_Index++].LoadString(IDS_GTD_WIZ_EXTENDED_MEMORYCARD); lC_Str_DriverArray[lui_Index++].LoadString(IDS_GTD_WIZ_SOUND_OP_UNIT); lC_Str_DriverArray[lui_Index].LoadString(IDS_GTD_WIZ_EXTERNAL_IO_UNIT); //Load error message AfxFormatStrings(lC_Str_Msg,IDS_GTD_WIZ_SET_STANDARD_CONTROLLER,(LPCTSTR*)lC_Str_DriverArray,10); Here after 9th String i am getting Problem. in %10 it is subtituting as %1 what to do. please help me out.

      Uday kiran

      J Offline
      J Offline
      jhwurmbach
      wrote on last edited by
      #2

      I would advise you to use boost::format[^] Boost is a library of very high standards. So high, parts of it will find its way into the upcoming C++ standard. It is completely free. Another possibility is building your message in a std::ostringstream, and get it from there.

      std::ostringstream stream;
      CString tmp;
      stream << _T("It is necessary to set one or more equipment other than ");
      stream << (LPCTSTR)tmp.LoadString(IDS_GTD_WIZ_CONTROLLER_BARCODE);
      ...
      std::string s = stream.str();
      CString s1 = s.c_str();


      Failure is not an option - it's built right in.

      U 1 Reply Last reply
      0
      • J jhwurmbach

        I would advise you to use boost::format[^] Boost is a library of very high standards. So high, parts of it will find its way into the upcoming C++ standard. It is completely free. Another possibility is building your message in a std::ostringstream, and get it from there.

        std::ostringstream stream;
        CString tmp;
        stream << _T("It is necessary to set one or more equipment other than ");
        stream << (LPCTSTR)tmp.LoadString(IDS_GTD_WIZ_CONTROLLER_BARCODE);
        ...
        std::string s = stream.str();
        CString s1 = s.c_str();


        Failure is not an option - it's built right in.

        U Offline
        U Offline
        uday kiran janaswamy
        wrote on last edited by
        #3

        hi jhwurmbach, I Understand your answer. But the Code T("It is necessary to set one or more equipment other than "); must not be hard coded and this is the String Table of the Resource with %1 %2 %3 ..... and Dynamically it must subtitute accordingly. please let me know any solution for this.

        Uday kiran

        J 1 Reply Last reply
        0
        • U uday kiran janaswamy

          hi jhwurmbach, I Understand your answer. But the Code T("It is necessary to set one or more equipment other than "); must not be hard coded and this is the String Table of the Resource with %1 %2 %3 ..... and Dynamically it must subtitute accordingly. please let me know any solution for this.

          Uday kiran

          J Offline
          J Offline
          jhwurmbach
          wrote on last edited by
          #4

          OK. I see. You got the text with the %1-replace markers inside and can not change it. How stupid! You could have a regex[^] exchanging all '%digit' by '%digit%' and use something like this

          cout << boost::format("writing %1%, x=%2% : %3%-th try") % "toto" % 40.23 % 50;
          // prints "writing toto, x=40.230 : 50-th try"

          (example from the boost-page) Ok. This idea comes out of desperation.


          Failure is not an option - it's built right in.

          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