string
String Utility API
This module provides utility functions for string manipulation and formatting.
Functions:
-
array_to_string
–Convert a numpy array to a formatted string.
-
sanitize_for_c_comment
–Sanitize a string for use in C block comments.
Copyright 2025 Ambiq. All Rights Reserved.
Functions
array_to_string
Generate csv like string from array.
Given a numpy array, this function converts it to a string representation with a specified number of elements per row. Useful for dumping data in C code.
Parameters:
-
data
NDArray
) –Data array
-
row_len
int
, default:20
) –Elements to write per row. Defaults to 20.
Returns:
-
str
(str
) –String representation of the array.
Example:
sanitize_for_c_comment
Sanitize a string (or bytes) so it can safely live inside a C block comment (/ ... /).
Transforms: - If bytes/bytearray, decode as UTF-8 (replacing errors). - Replaces '/' with '/ ' and '/' with ' /' - Strips out non-printable/control chars except tab/newline/carriage-return.
Parameters:
Returns:
-
str
(str
) –Sanitized text.