 
View Full Version : [VB] Togliere un carattere vuoto da una stringa (Formattazio
Dato la stringa: " Benvenuto Tom "
Vorrei inserire un controllo che mi toglie gli spazi vuoti e mi sostituisce con quello che voglio, in questo caso con un  " _ " , 
e quindi la frase diventa: " Benvenuto_Tom "
come si fa???
stringa="Buongiorno Tom"
stringa_new=Replace(stringa," ","_")
Bye !!
OK grazie,  
Come si fa per  sapere se la parola " Gatto " e' un Integer oppure una stringa ???
Originariamente inviato da race2 
[B]OK grazie,  
Come si fa per  sapere se la parola " Gatto " e' un Integer oppure una stringa ??? 
if isstring("gatto") = true then
   msgbox "Gatto è una parola come diavolo fa a essere un numero",vbinformation
else
   msgbox " "Gatto" non è una variabile stringa", vbcritical
end if
Originariamente inviato da xegallo 
[b]
if isstring("gatto") = true then
   msgbox "Gatto è una parola come diavolo fa a essere un numero",vbinformation
else
   msgbox " "Gatto" non è una variabile stringa", vbcritical
end if 
IsString() ???
Forse volevi dire:
   Dim var As String
   
   var = InputBox("Inserire un numero o una stringa")
   
   If IsNumeric(var) Then
      MsgBox "Il valore inserito è un numero"
   Else
      MsgBox "Il valore inserito è una stringa"
   End If
IsNumeric(var) ti dice solo se var può essere considerato un numero, senza distinguere tra Integer, Long, Single, Double, Currency...
Se il valore da inserire deve essere per forza Integer, si potrebbe forzare un cast intercettando l'errore, come fa questa funzione:
Public Function IsInteger(v As Variant) As Boolean
   Dim n As Integer
   Dim ret As Boolean
   
   On Error Resume Next
   n = CInt(v)
   
   If Err.Number <> 0 Then
      ret = False
   Else
      ret = (n = Val(v))    'non accetta valori con decimali
   End If
   
   On Error GoTo 0
   
   IsInteger = ret
End Function
OK, grazie mille domattina lo provo, ciao!
vBulletin® v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.