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. How do I work with the '\'

How do I work with the '\'

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionc++debuggingworkspace
5 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.
  • J Offline
    J Offline
    Jose Cruz
    wrote on last edited by
    #1

    My problem is: I´m trying to replace my file name from the CString wich value is "C:\esContaX\Archivos\TblPols.dbf" to finish with something like this: "C:\esContaX\Archivos\" using the following code: m_strAppPath.TrimRight('\'); , but I get the following errors: --------------------Configuration: esContaX - Win32 Debug-------------------- Compiling... esContaX.cpp C:\esContaX\esContaX.cpp(230) : error C2001: newline in constant C:\esContaX\esContaX.cpp(232) : error C2143: syntax error : missing ')' before 'return' C:\esContaX\esContaX.cpp(232) : warning C4305: 'argument' : truncation from 'const int' to 'char' C:\esContaX\esContaX.cpp(232) : warning C4309: 'argument' : truncation of constant value Error executing cl.exe. esContaX.exe - 2 error(s), 2 warning(s) Can somebody help me showing me how can I acomplish this.

    T S 2 Replies Last reply
    0
    • J Jose Cruz

      My problem is: I´m trying to replace my file name from the CString wich value is "C:\esContaX\Archivos\TblPols.dbf" to finish with something like this: "C:\esContaX\Archivos\" using the following code: m_strAppPath.TrimRight('\'); , but I get the following errors: --------------------Configuration: esContaX - Win32 Debug-------------------- Compiling... esContaX.cpp C:\esContaX\esContaX.cpp(230) : error C2001: newline in constant C:\esContaX\esContaX.cpp(232) : error C2143: syntax error : missing ')' before 'return' C:\esContaX\esContaX.cpp(232) : warning C4305: 'argument' : truncation from 'const int' to 'char' C:\esContaX\esContaX.cpp(232) : warning C4309: 'argument' : truncation of constant value Error executing cl.exe. esContaX.exe - 2 error(s), 2 warning(s) Can somebody help me showing me how can I acomplish this.

      S Offline
      S Offline
      spotofleopard
      wrote on last edited by
      #2

      '\\'

      1 Reply Last reply
      0
      • J Jose Cruz

        My problem is: I´m trying to replace my file name from the CString wich value is "C:\esContaX\Archivos\TblPols.dbf" to finish with something like this: "C:\esContaX\Archivos\" using the following code: m_strAppPath.TrimRight('\'); , but I get the following errors: --------------------Configuration: esContaX - Win32 Debug-------------------- Compiling... esContaX.cpp C:\esContaX\esContaX.cpp(230) : error C2001: newline in constant C:\esContaX\esContaX.cpp(232) : error C2143: syntax error : missing ')' before 'return' C:\esContaX\esContaX.cpp(232) : warning C4305: 'argument' : truncation from 'const int' to 'char' C:\esContaX\esContaX.cpp(232) : warning C4309: 'argument' : truncation of constant value Error executing cl.exe. esContaX.exe - 2 error(s), 2 warning(s) Can somebody help me showing me how can I acomplish this.

        T Offline
        T Offline
        Tim Smith
        wrote on last edited by
        #3

        "\" is an escape character in C-strings. Like "\n" for newline. Just double up the "\" to get a "\". "C:\\esContaX\\Archivos\\TblPols.dbf" Tim Smith "Programmers are always surrounded by complexity; we can not avoid it... If our basic tool, the language in which we design and code our programs, is also complicated, the language itself becomes part of the problem rather that part of the solution." Hoare - 1980 ACM Turing Award Lecture

        J 1 Reply Last reply
        0
        • T Tim Smith

          "\" is an escape character in C-strings. Like "\n" for newline. Just double up the "\" to get a "\". "C:\\esContaX\\Archivos\\TblPols.dbf" Tim Smith "Programmers are always surrounded by complexity; we can not avoid it... If our basic tool, the language in which we design and code our programs, is also complicated, the language itself becomes part of the problem rather that part of the solution." Hoare - 1980 ACM Turing Award Lecture

          J Offline
          J Offline
          Jose Cruz
          wrote on last edited by
          #4

          Ok this is the complete code CString strSection = "Files"; CString strStringItem = "DataFiles"; m_strAppPath= theApp.GetProfileString(strSection, strStringItem); // the value of m_strAppPath Now is = C:\esContaX\Archivos\TblPols.dbf TRACE(m_strAppPath.GetBuffer(m_strAppPath.GetLength())); //so trace shows C:\esContaX\Archivos\TblPols.dbf m_strAppPath.TrimRight('\\'); TRACE(m_strAppPath.GetBuffer(m_strAppPath.GetLength())); //Now trace shows the same value C:\esContaX\Archivos\TblPols.dbf return TRUE;

          E 1 Reply Last reply
          0
          • J Jose Cruz

            Ok this is the complete code CString strSection = "Files"; CString strStringItem = "DataFiles"; m_strAppPath= theApp.GetProfileString(strSection, strStringItem); // the value of m_strAppPath Now is = C:\esContaX\Archivos\TblPols.dbf TRACE(m_strAppPath.GetBuffer(m_strAppPath.GetLength())); //so trace shows C:\esContaX\Archivos\TblPols.dbf m_strAppPath.TrimRight('\\'); TRACE(m_strAppPath.GetBuffer(m_strAppPath.GetLength())); //Now trace shows the same value C:\esContaX\Archivos\TblPols.dbf return TRUE;

            E Offline
            E Offline
            Ernest Laurentin
            wrote on last edited by
            #5

            TrimRight would trim only from Right and the first character found is 'f', so it cannot remove any '\' character. but if your path was: "C:\esContaX\Archivos\TblPols.dbf\", it would remove it! Hope that helps! ÿVOTD:19 "My dear brothers, take note of this: Everyone should be quick to listen, slow to speak and slow to become angry, 20for man's anger does not bring about the righteous life that God desires." - Jam 1:19

            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