Differenze tra le versioni di "Conoscere il numero di occorrenze in una stringa con la funzione esterna PyUnicode Count() della libreria libpython3.4m.so.1.0"

Da Gambas-it.org - Wikipedia.
(Creata pagina con "La libreria ''libpython3.4m'' è un interfaccia in C di funzioni appartenenti alle risorse di Python. La funzione ''PyUnicode Count( )'' consente di sapere quante volte una s...")
 
 
Riga 1: Riga 1:
La libreria ''libpython3.4m'' è un interfaccia in C di funzioni appartenenti alle risorse di Python.
+
#redirect [[Conoscere_il_numero_di_occorrenze_in_una_stringa_con_la_funzione_esterna_PyUnicode_Count()_della_libreria_libpython3]]
 
 
La funzione ''PyUnicode Count( )'' consente di sapere quante volte una sub-stringa ricorre all'interno di una stringa.
 
 
 
Per poter fruire in Gambas di tale funzione esterna, è necessario richiamare la libreria dinamica condivisa: "''libpython3.4m.so.1.0''"
 
 
 
 
 
Mostriamo un semplice esempio pratico:
 
Library "libpython3.4m:1.0"
 
 
<FONT Color=gray>' ''(PyObject*) PyUnicode_FromString(const char *u)''
 
' ''Create a Unicode object from an UTF-8 encoded null-terminated char buffer u.''</font>
 
Private Extern PyUnicode_FromString(u As String) As Pointer
 
 
<FONT Color=gray>' ''(Py_ssize_t) PyUnicode_Count(PyObject *str, PyObject *substr, Py_ssize_t start, Py_ssize_t end)''
 
' ''Count the number of occurrences of substr in str[start:end].''</font>
 
Private Extern PyUnicode_Count(strp As Pointer, substr As Pointer, start As Long, endl As Long) As Long
 
 
 
'''Public''' Sub Main()
 
 
 
  Dim p, su As Pointer
 
  Dim s As String
 
  Dim i As Integer
 
   
 
  s = "testo testo testo testo"
 
   
 
  p = PyUnicode_FromString(s)
 
   
 
  su = PyUnicode_FromString("st")
 
   
 
  i = PyUnicode_Count(p, su, 0, String.Len(s))
 
  Print i
 
 
 
'''End'''
 
 
 
 
 
 
 
 
 
=Riferimenti=
 
* https://docs.python.org/3.4/c-api/unicode.html
 

Versione attuale delle 18:00, 1 mag 2020