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