Sorry if you don't know anything about Python, however the following snippet should be very readable for everyone. The only trick to pay attention to is that indexing the list with [-1] gives you the last item, if any, or throws an exception.
>>> fileName = 'TheFileName.Something.xMl' >>> fileNameList = fileName.split('.') >>> assert(len(fileNameList) > 1)
I need to convert this logic to C ++ (the language that I actually use, but still suck) with the following signature: void PopulateBackupFileNameOrDie(CAtlString& strBackupFileName, CAtlString& strXmlFileName); . Here strXmlFileName is "input", strBackupFileName "output" (should I undo a typo of two?). The tricky part is that (correct me if I'm wrong) I work with a Unicode string, so I am looking for these characters: .xmlXML not so straightforward. The latest Python does not have these problems because '.' and "." are Unicode strings (not "char" type) of length 1, both contain only a dot.
Note that the return type is void - don't worry about that. I do not want to tell you how we report the error to the user. In my Python example, I just used assert. You can do something similar or just include a comment, for example // ERROR: [REASON] .
Please ask if something is clear. Suggestions for using std::string , etc. Instead of a CAtlString for function parameters, this is not what I'm looking for. You can convert them inside a function if you need to, but I would prefer not to mix different types of strings in one function. I am compiling this C ++ on Windows using VS2010. This means that I do NOT install BOOST , QTString or other libraries that are not available out of the box. Stealing a BOOST or other heading to turn on some magic is also not the right solution.
Thanks.
source share