Differenze tra le versioni di "Verificare se in una stringa vi sono caratteri non stampabili"
Da Gambas-it.org - Wikipedia.
Riga 1: | Riga 1: | ||
In Gambas attualmente non esiste una specifica funzione per sapere se un carattere è stampabile o meno. | In Gambas attualmente non esiste una specifica funzione per sapere se un carattere è stampabile o meno. | ||
<BR>Ricordiamo che un carattere stampabile non è un ''carattere di controllo'', e pertanto è compreso fra il num. 32 ed il num. 126 del codice ASCII. | <BR>Ricordiamo che un carattere stampabile non è un ''carattere di controllo'', e pertanto è compreso fra il num. 32 ed il num. 126 del codice ASCII. | ||
− | |||
Sarà possibile adottare una modalità che prevede l'uso delle sole risorse di Gambas, come l'esempio di codice che segue: | Sarà possibile adottare una modalità che prevede l'uso delle sole risorse di Gambas, come l'esempio di codice che segue: | ||
Riga 10: | Riga 9: | ||
Dim v As Boolean | Dim v As Boolean | ||
− | + | s = "Testo\nqualsiasi" | |
− | + | For b = 1 To String.Len(s) - 1 | |
− | + | Select Case Asc(s, b) | |
− | + | Case 31 To 126 | |
− | + | v = False | |
− | + | Case Else | |
− | + | v = True | |
− | + | Break | |
− | + | End Select | |
− | + | Next | |
− | + | Print v | |
'''End''' | '''End''' | ||
− | + | oppure utilizzare la funzione "[[Isprint()|IsPrint()]]" del linguaggio C: | |
− | oppure utilizzare la funzione [[Isprint()| | ||
− | |||
− | |||
− | |||
<FONT Color=gray>' ''int isprint(int c)'' | <FONT Color=gray>' ''int isprint(int c)'' | ||
' ''Check whether the passed character is printable.''</font> | ' ''Check whether the passed character is printable.''</font> | ||
Riga 42: | Riga 37: | ||
Dim b As Byte | Dim b As Byte | ||
− | + | bb = Byte[].FromString(s) | |
− | + | For Each b In bb | |
− | + | Print CBool(isprint(CInt(b))) | |
− | + | Next | |
'''End''' | '''End''' |
Versione delle 20:10, 11 mag 2023
In Gambas attualmente non esiste una specifica funzione per sapere se un carattere è stampabile o meno.
Ricordiamo che un carattere stampabile non è un carattere di controllo, e pertanto è compreso fra il num. 32 ed il num. 126 del codice ASCII.
Sarà possibile adottare una modalità che prevede l'uso delle sole risorse di Gambas, come l'esempio di codice che segue:
Public Sub Main() Dim s As String Dim b As Byte Dim v As Boolean s = "Testo\nqualsiasi" For b = 1 To String.Len(s) - 1 Select Case Asc(s, b) Case 31 To 126 v = False Case Else v = True Break End Select Next Print v End
oppure utilizzare la funzione "IsPrint()" del linguaggio C:
' int isprint(int c) ' Check whether the passed character is printable. Private Extern isprint(num As Integer) As Integer In "libc:6" Public Sub Main() Dim s As String = "Testo\nqualsiasi" Dim bb As Byte[] Dim b As Byte bb = Byte[].FromString(s) For Each b In bb Print CBool(isprint(CInt(b))) Next End