StrCpy: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
m removing new tags from 2.6.0 |
m →Example: Formatting |
||
| (One intermediate revision by the same user not shown) | |||
| Line 3: | Line 3: | ||
==Usage== |
==Usage== |
||
Copy a ''source'' string to a ''destination'' array as a series of characters. Optionally, the copy can start from a given index in the source string. |
Copy a ''source'' string to a ''destination'' array as a series of characters. Optionally, the copy can start from a given index in the source string. |
||
{{verification}} |
|||
==Return Value== |
==Return Value== |
||
True if the entire string (or substring) was successfully copied to the array; false if the copy ran out of room or if a negative ''source_index'' was given. |
True if the entire string (or substring) was successfully copied to the array; false if the copy ran out of room or if a negative ''source_index'' was given. |
||
==Example== |
==Example== |
||
This function returns true if the map lump is in the form "ExMx". It copies the string to a char array, then it compares individual characters at 2 positions, and skips the character in {{c|IsMap_LumpChar[1]}}. |
|||
{{noexamples}} |
|||
int IsMap_LumpChar[8]; |
|||
str IsMap_LumpStr; |
|||
function bool IsMap_EXMX (void) |
|||
{ |
|||
if([[StrCpy]](a:IsMap_LumpChar, IsMap_LumpStr)) |
|||
{ |
|||
int c_e = IsMap_LumpChar[0]; |
|||
int c_m = IsMap_LumpChar[2]; |
|||
return( (c_e == 'e' || c_e == 'E') && (c_m == 'm' || c_m == 'M') ); |
|||
} |
|||
return {{const|false}}; |
|||
} |
|||
[[category:ACS String operations]] |
[[category:ACS String operations]] |
||
Latest revision as of 01:34, 26 October 2013
bool StrCpy (a:destination, string source[, int source_index]);
Usage
Copy a source string to a destination array as a series of characters. Optionally, the copy can start from a given index in the source string.
Return Value
True if the entire string (or substring) was successfully copied to the array; false if the copy ran out of room or if a negative source_index was given.
Example
This function returns true if the map lump is in the form "ExMx". It copies the string to a char array, then it compares individual characters at 2 positions, and skips the character in IsMap_LumpChar[1].
int IsMap_LumpChar[8];
str IsMap_LumpStr;
function bool IsMap_EXMX (void)
{
if(StrCpy(a:IsMap_LumpChar, IsMap_LumpStr))
{
int c_e = IsMap_LumpChar[0];
int c_m = IsMap_LumpChar[2];
return( (c_e == 'e' || c_e == 'E') && (c_m == 'm' || c_m == 'M') );
}
return FALSE;
}