Insert core::string into the middle of another core::string

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
vroomhenderson
Posts: 6
Joined: Mon Jan 05, 2015 5:44 pm

Insert core::string into the middle of another core::string

Post by vroomhenderson »

So, I need to load a series of images (which could change in between run time). I have a pre-programmed file template as such: "Loading_Screen/%%%.png". The program needs to parse the string and replace the '%' character with the correct digit. A resulting string should be something like: "Loading_Screen/053.png".

Now, since I need an io::path object for device->getVideoDriver()->getTexture() and I can't find any way to convert an std::string to either an io::path or core::string, I need to start out with using core::string.

By looking at the source for core::string, I can see that there's methods for finding, replacing, and deleting from the string. Sounds like replacing might be what I need except for one issue: the replace method replaces everything with that character. So, when I try to change the first % to a 0, it'll turn to 000.png rather than the desired 0%%.png.

So, since I need more precise editing, I figure I'll have to do it myself. But then I realized that there's no method for inserting into a core::string! Am I missing something?

Thank you for the help!
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Insert core::string into the middle of another core::str

Post by hendu »

This really is a job for the good old C api. C++ classes were never good with mangling like that.

Code: Select all

 
char buffer[80];
snprintf(buffer, 80, "Loading_Screen/%03d.png", number);
vroomhenderson
Posts: 6
Joined: Mon Jan 05, 2015 5:44 pm

Re: Insert core::string into the middle of another core::str

Post by vroomhenderson »

Thank you! You're suggestion worked! :D
Post Reply