Strings
See also
- StringFunctions (String Manipulation Class)
StringFunctions
StringFunctions.len()
StringFunctions.substr()
StringFunctions.head()
StringFunctions.tail()
StringFunctions.right()
StringFunctions.left()
StringFunctions.is_name()
StringFunctions.alias()
StringFunctions.alias_list()
StringFunctions.references()
StringFunctions.is_point_process()
StringFunctions.is_artificial()
- String Parsing (sscanf)
- sprint()
- Syntax:
n.sprint(strdef, "format", args)
- Description:
Prints to a NEURON (i.e. not Python) string. See
printf()
for the description of the format.
Example:
from neuron import n strdef = n.ref('') n.sprint(strdef, 'There are %d %s.', 3, 'dendrites') print(strdef[0])
Note
Similar functionality is available for Python strings using the
%
operator or (for Python 2.6+) a string object’sformat
method or (for Python 3.6+) with f-strings. As Python strings are immutable, these approaches each create a new string.We can also use f-strings to update NEURON strings by writing to
strdef[0]
; for example:from neuron import n strdef = n.ref('') num_parts = 3 part = "dendrites" strdef[0] = f'There are {num_parts} {part}.' print(strdef[0])
- Syntax:
sprint(strdef, "format", args)
- Description:
Prints to a string. See
printf()
for the description of the format.
- strcmp()
- Syntax:
x = n.strcmp("string1", "string2")
- Description:
Returns negative, 0, or positive value depending on how the strings compare lexicographically. 0 means they are identical. A positive value indicates
string1
comes afterstring2
. This is a thin wrapper around the C standard library functionstrcmp
and returns the same values it would return.Note:
string1
andstring2
must contain only ASCII characters. All strings (whether or not they contain unicode) may be compared directly in Python via<
,>
,==
, etc.For example
"apical" < "basal"
would returnTrue
.Note that accented characters are not treated as equal to their non-accented counterparts. For example,
"soma" == "sóma"
would returnFalse
. If you wish for accented and non-accented characters to be compared equal, one solution would be to use the third-partyunidecode
module, available viapip install unidecode
, to remove accents before running the comparison.
- Syntax:
x = strcmp("string1", "string2")
- Description:
return negative, 0, or positive value depending on how the strings compare lexicographically. 0 means they are identical.