05 Feb, 2009, Skol wrote in the 1st comment:
Votes: 0
I'm having a complete brainfart.
I'm working on an OLC update and wanted to strip out 'spec_' from a listing so it's simply 'fido' instead of 'spec_fido'.

Of course I can do a for loop with i = 5, j=0 and just copy starting at the 5th char in the string, but… Isn't there a function to chop (like chomp in PHP) the FRONT part of a string off?
It's not something I use a lot, but I thought I'd used something like that in the past.

Ie (blah) sprintf (temp, "%s", skip_crap(oldstring, "spec_")) etc.

Although, I suppose I could simply make one that skips X characters. I just thought I'd seen something that'd allow me to show a string starting at like string[8] or such until '\0'.
05 Feb, 2009, Skol wrote in the 2nd comment:
Votes: 0
What I'd done, in patch, was this:
char temp[256]; // store spec name minus 5 chars 'spec_'
sprintf (buf, "%s", spec_name (pMobIndex->spec_fun));

int i,j;

for (i=5,j=0; buf[i]!= '\0'; i++)
{
temp[j] = buf[i];
j++;
}
temp[j]='\0'; // terminate string


Then called that string:
sprintf( buf, "[%5d-%3d] %-10.9s (%-8.7s)",
pMobIndex->vnum, pMobIndex ? pMobIndex->level:0, smash_color( pMobIndex->short_descr), temp);
05 Feb, 2009, David Haley wrote in the 3rd comment:
Votes: 0
printf(str+8) will print the string "str" starting at the 8th character. Not as nice as a function that strips off an explicit string prefix, but…

Keep in mind that a string is nothing more than a sequence of characters starting somewhere and going until a zero byte.
05 Feb, 2009, Skol wrote in the 4th comment:
Votes: 0
Right on, thanks David. I was wondering the same heh, I mean it's just an array of chars, start at X char and go from there.

Ended up with:
sprintf( buf, "[%5d-%3d] %-10.9s (%-8.7s)",
pMobIndex->vnum, pMobIndex ? pMobIndex->level:0,
smash_color( pMobIndex->short_descr),
spec_name (pMobIndex->spec_fun) + 5);

Since I didn't need to manipulate the string, simply show from [5] onward, I don't need to store it in a character or anything. (smash_color is a lopes colour remover I'd written if anyone needs it).

Thanks David, I appreciate it.
0.0/4