Substring on an orxSTRING?

edited November 2015 in Help request
Is there a way to get a substring on an orxSTRING? For example:

CATDOGFISH

I'd like to extract DOG. So from index 3, and a length of 3.

I can use std::string functions and convert, but curious to know of a pure Orx function.

Comments

  • edited November 2015
    There's no pure orx function for that, unfortunately, but I can add one. It'll rely on C support for string though, ie. almost none. :)
    Basically it'll allocate a new buffer (you'll be responsible for deleting it) and copy the substring into it, with a 0 terminal character.
    One of the very very old items on my todo list is to add support for dual marker strings, ie. string that are not defined by address + 0-termination but by two addresses: start and stop.

    That has many advantages like cheap length computation, in-place substrings, etc... One day, maybe!
  • edited November 2015
    Certainly don't do it for me but if you can see a lot of need for others to do this, then it would be good to have.

    I solved it by converting to a std::string and doing a substr then converting back to orxSTRING.
  • edited November 2015
    I needed to define such strings for the animation graph package on orxhub. Having utilities for them in orx would be great, especially when one is trying to stay away from STL, but what would be even greater is if certain basic orx functions had dual marker string versions. Like if orxString_GetID supported them, many tasks could be handled safely and efficiently with dual marker strings only.
  • edited December 2015
    Incredibly late reply, but why don't you use orxString_NPrint? Just give it size + 1 (for the '') and the entry + pos as the argument. It should work fine.
        orxU32 size = 3, pos = 3;
        orxSTRING testing = "CATDOGFISH";
        char buffer[64];
        orxString_NPrint(buffer, size + 1, "%s", testing + pos);
    
Sign In or Register to comment.