Differenze tra le versioni di "Porre a "Null" tutti gli elementi di un vettore di tipo Stringa"
Da Gambas-it.org - Wikipedia.
Riga 70: | Riga 70: | ||
' ''Copies the character c (an unsigned char) to the first n characters of the string pointed to by the argument "str".''</font> | ' ''Copies the character c (an unsigned char) to the first n characters of the string pointed to by the argument "str".''</font> | ||
Private Extern memset(dest As Pointer, c As Integer, count As Integer) As Pointer | Private Extern memset(dest As Pointer, c As Integer, count As Integer) As Pointer | ||
− | + | ||
<FONT color=gray>' ''void exit(int status)'' | <FONT color=gray>' ''void exit(int status)'' | ||
' ''Terminates the calling process immediately. Any open file descriptors belonging to the process are closed.''</font> | ' ''Terminates the calling process immediately. Any open file descriptors belonging to the process are closed.''</font> |
Versione delle 13:26, 26 gen 2015
Per azzerare tutti gli elementi di una variabile vettoriale (array) di tipo Stringa, è possibile utilizzare almeno le modalità che di seguito si espongono.
Assegnare il valore Null mediante un ciclo
Public Sub Main() Dim ss As String[] = ["a", "b", "c", "d", "e"] Dim b As Byte For b = 0 To ss.Max ss[b] = Null Next End
Public Sub Main() Dim ss As String[] = ["a", "b", "c", "d", "e"] Dim b As Byte While b < ss.Count ' Il ciclo continua finché "b" è minore di 5 ss[b] = Null Inc b Wend End
Public Sub Main() Dim ss As String[] = ["a", "b", "c", "d", "e"] Dim b As Byte Do ss[b] = Null Inc b ' Il ciclo continua finché "b" non è uguale a 5: Loop Until b = ss.Count End
Modalità con il metodo .Fill()
Public Sub Main() Dim ss As String[] = ["a", "b", "c", "d", "e"] ss.Fill(Null, 0, ss.Count) End
Modalità con la funzione esterna di C: memset ()
E' possibile utilizzare anche la funzione esterna di C: "memset()", dichiarando sia la funzione medesima mediante Extern, sia la libreria C, nella quale essa è contenuta.
Library "libc:6" ' void *memset(void *str, int c, size_t n) ' Copies the character c (an unsigned char) to the first n characters of the string pointed to by the argument "str". Private Extern memset(dest As Pointer, c As Integer, count As Integer) As Pointer ' void exit(int status) ' Terminates the calling process immediately. Any open file descriptors belonging to the process are closed. Private Extern exit_C(status As Integer) Exec "exit" Public Sub Main() Dim ss As String[] = ["a", "b", "c", "d", "e"] Dim b As Byte ' La funzione "memset" carica un valore in tutti i byte di un'area di memoria: memset(ss.Data, 0, ss.Count * SizeOf(gb.String)) ' Verifichiamo in console il risultato: For b = 0 To ss.Max Print ss[b] Next exit_C(0) End