Strings...
What's the EQemu function for selecting certain letters from a string? Doesn't have a substr, as far as I can see, so I was wondering what's being used instead.
|
You mean from inside of an EQ client? Or from c code? If you mean c code, there's always strstr (man strstr for info) or strchr (man strchr for info). I don't know if someone wrote a specialized string searching function inside the EMU, but it would probably be hard to beat one of the built in functions as far as performance.
|
Yeah, from the C code. Specifically, selecting the "00" etc from an NPC name. I'm trying to cut that off in the GetName() function.
"man"? Sorry, you're dealing with someone with four weeks of C++ experience, heh. |
man is a command you can use to find information about various things, from other commands to system calls and more. man is short for manual, but it's only available (AFAIK) on UNIX style systems (Linux, MacOSX, etc).
As far as finding the "00" in a null terminated string, you'll probably want to use strstr. strstr takes two parameters: the string to search and the string to search for. It returns a pointer to the position in the first string where the second string is located (or NULL if it's not found). For example: Code:
char[256] name = "Some name00"; To better answer your original question, however, if you wanted to delete the "00" in the name above, you would strstr for "00" and if it was found (return value is not NULL), then deference the pointer and set it to '\0' (the null character): Code:
char* found = strstr(name, "00"); Also, if you do change the data in the string, you should be sure to copy it first or it will change the data in the class (which you probably don't want :)) HTH |
Exactly what I was looking for, thanks a ton!
|
All times are GMT -4. The time now is 10:59 AM. |
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.