Example:
from neuron import h sf = h.StringFunctions()
from neuron import h
s = h.ref("hello")
sf = h.StringFunctions()
length = sf.len(s)
print length
from neuron import h
s1 = h.ref("allowed")
s2 = h.ref("low")
sf = h.StringFunctions()
index = sf.substr(s1, s2)
from neuron import h
s1 = h.ref("hello world")
s2 = h.ref("")
sf = h.StringFunctions()
index = sf.head(s1, "[e]", s2)
print s2[0]
The result contains the tail of the string from the char following regexp to the end of the string. return index of first char.
Other functions can be added as needed, eg., index(s1, c1), char(s1, i), etc. without polluting the global name space. In recent versions functions can return strings.
from neuron import h
s1 = h.ref("hello world")
s2 = h.ref("")
sf = h.StringFunctions()
index = sf.tail(s1, "[e]", s2)
print s2[0]
from neuron import h
s = h.ref("hello")
sf = h.StringFunctions()
sf.right(s, 3)
print s[0]
from neuron import h
s = h.ref("hello")
sf = h.StringFunctions()
sf.left(s, 3)
print s[0]
from neuron import h
s1 = h.ref("hello world")
sf = h.StringFunctions()
name = sf.is_name(s1)
print name
Here is an example with one string that works, and another that does not:
from neuron import h sf = h.StringFunctions() # valid name print sf.is_name("xvalue") # invalid name print sf.is_name("xsquiggle")
.alias(obj, "name", &var2)
.alias(obj, "name", obj2)
.alias(obj, "name")
.alias(obj)
from neuron import h
sf = h.StringFunctions()
v = h.Vector()
sf.alias(v, 't', h._ref_t)
print('v.t = %g' % v.t)
h.t = 42
print('v.t = %g' % v.t)
Warning
The String class is not a built-in class. It generally gets declared when the nrngui.hoc file is loaded and lives in stdlib.hoc. Note that the String class must exist and its constructor must allow a single strdef argument. Minimally:
from neuron import h
h.load_file('stdrun.hoc')
sf = h.StringFunctions()
v = h.Vector()
al = sf.alias_list(v)
print al
from neuron import h
s1 = h.Section(name='soma')
strobj = h.StringFunctions()
strobj.references(s1)
from neuron import h
h.load_file('stdrun.hoc')
s1 = h.Section(name='soma')
syn = h.ExpSyn(s1(0.5))
sf = h.StringFunctions()
# not point process
print sf.is_point_process(s1)
# point process
print sf.is_point_process(syn)
c = h.IntFire1()
# point process
print ssf.is_point_process(c)
from neuron import h
h.load_file('stdrun.hoc')
s1 = h.Section(name='soma')
syn = h.ExpSyn(s1(0.5))
# initiate string function
sf = h.StringFunctions()
c = h.IntFire1()
# artificial
print sf.is_artificial(c)
# not artificial
print sf.is_artificial(syn)