0

I have a string that has multiple file paths like as shown below:

%programdata%\EMR\Registration\Registration_EMR.xml C:\ProgramData\EMR\Registration\RegistrationEMR.xml
%AppData%\EMR\EMR Setup\REGDATA\registration_EMR.xml %AppData%\EMR\EMR Setup\REGDATA\RegistrationEMR.xm

I wanted to loop through the string by separating the file paths with space(' ') and store it into the vector/array.

so that the vector/array contains the below path that is separated with space.

%programdata%\EMR\Registration\Registration_EMR.xml 
C:\ProgramData\EMR\Registration\RegistrationEMR.xml
%AppData%\EMR\EMR Setup\REGDATA\registration_EMR.xml 
%AppData%\EMR\EMR Setup\REGDATA\RegistrationEMR.xml

Could anyone please help me?

Updated code:

I modified the ReadJsonFile function like as shown below to split the file paths after each .xml, then calling ExpandEnvironmentStrings and then storing each file path into the vector.

I am facing difficulty to tokenize the string as we can tokenize only char*.

I am getting the below errors:

argument of type "const WCHAR *" is incompatible with parameter of type "char *" no instance of overloaded function "ExpandEnvironmentStringsW" matches the argument list

bool EMRFileReader::ReadJsonFile(const std::wstring &strFilePath, std::wstring &strFileContent)
{ 
std::vector<std::wstring> pathsVector;  
const WCHAR *wpszPathToSearch = strFilePath.c_str();    
TCHAR szOut[MAX_PATH];  
char *token = strtok(wpszPathToSearch, ".xml");  
//argument of type "const WCHAR *" is incompatible with parameter of type "char *"  
while (token != NULL)   
{       
ExpandEnvironmentStrings(token, szOut, ARRAYSIZE(szOut)); 
//no instance of overloaded function "ExpandEnvironmentStringsW" matches the argument list

pathsVector.push_back(szOut);   
}
return true;
}
John Paul Coder
  • 313
  • 1
  • 12
  • What have you tried and what are the results? – schaiba Dec 01 '19 at 07:43
  • Does this answer your question? [C++: splitting a string into an array](https://stackoverflow.com/questions/16029324/c-splitting-a-string-into-an-array) – Andrew Truckle Dec 01 '19 at 07:45
  • Do you need to have quotes around a path that has a space in it like the last two? – Marichyasana Dec 01 '19 at 08:27
  • 1
    As long as you do not give additional information about the pattern of the path names, there will be NO solution to your problem. It is not possible to distinguish between the separator "space" and a "space" in the file/pathname. If you would give an additional condition, like, a pathname must have a dot in it, then it would be possible. The indicated link: https://stackoverflow.com/questions/16029324/c-splitting-a-string-into-an-array will not help (besides, I would never use any of the answers in that linked article. How can the accepted solution have so many upvotes?). – A M Dec 01 '19 at 08:47
  • Paths may have embedded spaces. It is a bad idea to separate them with a space. – n. m. could be an AI Dec 01 '19 at 09:55
  • I updated the code to tokenize and store the string paths with .xml into the vector. But I am getting some error messages. could anyone please help me? – John Paul Coder Dec 01 '19 at 16:55

0 Answers0