Strings manipulation¶
List of available functions¶
Examples¶
A few examples are given below
import wilfried.utilities.strings as st
data = [1, 2, 3, 5.5]
print(data)
# Transform data into list of strings
data_str = st.toStr(data)
print(data_str)
# Compute the length of each string in the list
data_len = st.computeStringsLen(data_str)
print(data_len)
# Compute the length of the longest string in the list
maxLen = st.maxStringsLen(data_str)
print(maxLen)
# Combine strings from the list into a single string
string = st.putStringsTogether(data_str)
print(string)
Documentation¶
Code author: Wilfried Mercier - IRAP <wilfried.mercier@irap.omp.eu>
String related functions.
- utilities.strings.computeStringsLen(listStrings)[source]¶
Code author: Wilfried Mercier - IRAP <wilfried.mercier@irap.omp.eu>
For each string in the list, compute its length and return them all.
- Parameters
listStrings (list[str]) – list of strings
- Returns
list with the length for each string
- Return type
list
- utilities.strings.maxStringsLen(listStrings)[source]¶
Code author: Wilfried Mercier - IRAP <wilfried.mercier@irap.omp.eu>
For each string in the list, compute its length and return the maximum value.
- Parameters
listStrings (list[str]) – list of strings
- Returns
the length of the longest string
- Return type
int
- utilities.strings.putStringsTogether(listStrings)[source]¶
Code author: Wilfried Mercier - IRAP <wilfried.mercier@irap.omp.eu>
Combine strings from a list with a newline character (\n) between each string (except after the final one).
- Parameters
listStrings (list[str]) – list of strings to combine
- Returns
the combined strings as formatted text
- Return type
str
- utilities.strings.toStr(listStuff)[source]¶
Code author: Wilfried Mercier - IRAP <wilfried.mercier@irap.omp.eu>
Transform a list of values into a list of strings.
- Parameters
listStuff (list) – list whose elements will be transformed into strings
- Returns
the input list as a list of strings
- Return type
list[str]