Sscanf
SA:MP sscanf plugin originally made by @Y-Less
Install / Use
/learn @Y-Less/SscanfREADME
sscanf 2.15.1
Introduction
This is the sscanf plugin, which provides the sscanf function to extract basic structured data from strings. This is slightly different to regular expressions, but both have their place. A regular expression gives you total control over the exact structure of data down to the character level; however, extracting structured data like numbers using it is tricky. Conversely this gives slightly higher-level "specifiers" which can easily extract data types, at the expense of fine-grained control. To convert a string in to two numbers would look like:
new num1, num2;
sscanf("45 100", "ii", num1, num2);
ii is the specifier string, which here means "integer integer"; stating that the input string should be two whole numbers in a row (which is - "45 100"). num1 and num2 are the destination variables to store the found numbers in (after conversion from strings). You can check if the conversion failed by looking for a non-naught return value:
new num1, num2;
if (sscanf("hello 100", "ii", num1, num2))
{
printf("The input was not two numbers.");
}
This will fail because "hello" is not a whole number (or indeed any type of number at all). For more information on using the function refer to the tutorials or the reference documentation below:
Contents
- 1 Introduction
- 2 Contents
- 3 Downloads
- 4 Use
- 4.1 Scripting
- 4.2 open.mp
- 4.3 SA:MP Windows
- 4.4 SA:MP Linux
- 4.5 NPC Modes
- 5 Tutorials
- 5.1
/sendcashCommand - 5.2 INI Parser
- 5.3 Error Detection
- 5.4 A Basic Shop
- 5.1
- 6 Specifiers
- 6.1 Strings
- 6.2 Packed Strings
- 6.3 Arrays
- 6.4 Enums
- 6.5 Provided Lengths
- 6.6 Quiet
- 6.7 Searches
- 6.8 Enums
- 6.9 Delimiters
- 6.10 Optional specifiers
- 6.11 Users
- 6.12 Custom (kustom) specifiers
- 6.13 Colours
- 6.14 End Of Input
- 7 Options
- 7.1 OLD_DEFAULT_NAME:
- 7.2 MATCH_NAME_PARTIAL:
- 7.3 CELLMIN_ON_MATCHES:
- 7.4 SSCANF_QUIET:
- 7.5 OLD_DEFAULT_KUSTOM:
- 7.6 SSCANF_ALPHA:
- 7.7 SSCANF_COLOUR_FORMS:
- 7.8 SSCANF_ARGB:
- 7.9 MATCH_NAME_FIRST:
- 7.10 MATCH_NAME_SIMILARITY:
- 7.11 ERROR_CODE_IN_RET:
- 7.12 WARNINGS_AS_ERRORS:
- 7.13 ERROR_CATEGORY_ONLY:
- 8
extract - 9 Similarity
- 10 Error Returns
- 10.1 Additional Codes
- 10.2 Error Categories
- 11 Alternates
- 12 All Specifiers
- 13 Full API
- 13.1
sscanf(const data[], const format[], {Float, _}:...); - 13.2
unformat(const data[], const format[], {Float, _}:...); - 13.3
SSCANF_Option(const name[], value); - 13.4
SSCANF_Option(const name[]); - 13.5
SSCANF_SetOption(const name[], value); - 13.6
SSCANF_GetOption(const name[], value); - 13.7
SSCANF_Version(version[], size = sizeof (version)); - 13.8
SSCANF_Version(); - 13.9
SSCANF_VersionString(version[], size = sizeof (version)); - 13.10
SSCANF_VersionBCD(); - 13.11
SSCANF_Levenshtein(const string1[], const string2[]); - 13.12
Float:SSCANF_TextSimilarity(const string1[], const string2[]); - 13.13
SSCANF_GetClosestString(const input[], const candidates[][], threshold = cellmax, count = sizeof (candidates)); - 13.14
SSCANF_GetClosestValue(const input[], const candidates[][], const results[], fail = cellmin, threshold = cellmax, count = sizeof (candidates), check = sizeof (results)); - 13.15
SSCANF_GetSimilarString(const input[], const candidates[][], Float:threshold = 0.111111, count = sizeof (candidates)); - 13.16
SSCANF_GetSimilarValue(const input[], const candidates[][], const results[], fail = cellmin, Float:threshold = 0.111111, count = sizeof (candidates), check = sizeof (results)); - 13.17
SSCANF_VERSION_STRING - 13.18
SSCANF_VERSION_BCD - 13.19
SSCANF_VERSION - 13.20
SSCANF_NO_K_VEHICLE - 13.21
SSCANF_NO_K_WEAPON - 13.22
SSCANF_NO_NICE_FEATURES - 13.23
SSCANF_GetLastError(); - 13.24
SSCANF_ClearLastError(); - 13.25
sscanf_error:SSCANF_GetErrorCategory(error); - 13.26
SSCANF_GetErrorSpecifier(); - 13.27
SSCANF_Debug();`
- 13.1
- 14 Errors/Warnings
- 14.1 MSVRC100.dll not found
- 14.2 sscanf error: System not initialised
- 14.3 sscanf warning: String buffer overflow.
- 14.4 sscanf warning: Optional types invalid in array specifiers, consider using 'A'.
- 14.5 sscanf warning: Optional types invalid in enum specifiers, consider using 'E'.
- 14.6 sscanf error: Multi-dimensional arrays are not supported.
- 14.7 sscanf error: Search strings are not supported in arrays.
- 14.8 sscanf error: Delimiters are not supported in arrays.
- 14.9 sscanf error: Quiet sections are not supported in arrays.
- 14.10 sscanf error: Unknown format specifier '?'.
- 14.11 sscanf warning: Empty default values.
- 14.12 sscanf warning: Unclosed default value.
- 14.13 sscanf warning: No default value found.
- 14.14 sscanf warning: Unenclosed specifier parameter.
- 14.15 sscanf warning: No specified parameter found.
- 14.16 sscanf warning: Missing string length end.
- 14.17 sscanf warning: Missing length end.
- 14.18 sscanf error: Invalid data length.
- 14.19 sscanf error: Invalid character in data length.
- 14.20 sscanf error: String/array must include a length, please add a destination size.
- 14.21 sscanf warning: Can't have nestled quiet sections.
- 14.22 sscanf warning: Not in a quiet section.
- 14.23 sscanf warning: Can't remove quiet in enum.
- 14.24 sscanf error: Arrays are not supported in enums.
- 14.25 sscanf warning: Unclosed string literal.
- 14.26 sscanf warning: sscanf specifiers do not require '%' before them.
- 14.27 sscanf error: Insufficient default values.
- 14.28 sscanf error: Options are not supported in enums.
- 14.29 sscanf error: Options are not supported in arrays.
- 14.30 sscanf error: No option value.
- 14.31 sscanf error: Unknown option name.
- 14.32 sscanf warning: Could not find function SSCANF:?.
- 14.33 [sscanf error: SSCANF_
