2024-12-08 02:15 PM
Hi, I see these functions have essentially the same functionality, is there any recommendation on which to use?
I understand snprintf has the advantage of formatting other data types into the string, but for simple string = string functionality, does it matter which is used? I notice doing UnicodeChar a = UnicodeChar b also works.
2024-12-12 01:21 AM
Hello @Priyank ,
strncpy: Use with caution for ASCII strings; not suitable for Unicode.
snprintf: Preferred for both ASCII and Unicode strings with proper encoding handling.
snprintf is a safer alternative to sprintf that allows you to specify the maximum number of characters to write to the destination buffer, including the null terminator. It can be used for formatted output and is more versatile than strncpy.
Regards
2024-12-16 09:53 AM
Hi, it seems Unicode:: has a strncpy, is it still not suitable even if it is apart of the Unicode library?
static uint16_t strncpy(UnicodeChar* RESTRICT dst, const char* RESTRICT src, uint16_t maxchars);
* Integer to ASCII conversion. Supports radix 2 to radix 36.
*
* @param value to convert.
* @param [out] buffer to place result in.
* @param bufferSize Size of buffer (number of UnicodeChar's).
* @param radix to use (8 for octal, 10 for decimal, 16 for hex)