Pour savoir si la chaine comporte des nombres.

Résolu
cs_domxaline Messages postés 327 Date d'inscription jeudi 21 août 2008 Statut Membre Dernière intervention 10 mai 2012 - 30 janv. 2009 à 09:28
cs_domxaline Messages postés 327 Date d'inscription jeudi 21 août 2008 Statut Membre Dernière intervention 10 mai 2012 - 4 févr. 2009 à 09:49
bojour
dans ce prg qui suit quel code je dois écrire, pour savoir si la chaine comporte des nombres:

Private

Sub Button3_Click(
ByVal sender
As System.Object,
ByVal e
As System.EventArgs)
Handles Button3.Click

Dim SomeString
As
String

Dim OneCharacter
As
Char

Dim FirstName
As
String

Dim i
As
Integer

Dim TextLength
As IntegerSomeString "George123"FirstName SomeString

OneCharacter = SomeString.Chars(2)

For i = 0
To FirstName.Length - 1
OneCharacter = FirstName.Chars(i)

MsgBox(OneCharacter)

Next i

End
Sub End

Class

9 réponses

cs_Exploreur Messages postés 4821 Date d'inscription lundi 11 novembre 2002 Statut Membre Dernière intervention 15 novembre 2016 15
3 févr. 2009 à 22:46
Salut,

Faudrait un peu regarder ce QUE fait le code que je te donne quand même ^^ .... 2 lignes à enlever....

Private Sub Form_Load()

Dim YouString   As String
Dim NextString  As String
Dim iBoucle     As Integer
Dim iNbrChiffre As Integer
Dim iNbrChar    As Integer

YouString = "Tata123titi"

For i = 1 To Len(YouString)
    NextString = Mid(YouString, i, 1)
    If IsNumeric(NextString) Then
       iNbrChiffre = iNbrChiffre + 1
    Else
       iNbrChar = iNbrChar + 1
    End If
    ' ...
Next i

MsgBox "Nombres de numériques : " & iNbrChiffre
MsgBox "Nombres de caractères : " & iNbrChar

End Sub

Ps : Pense à valider quand une réponse résous ton problème

A+
Exploreur

 Linux a un noyau, Windows un pépin
    ** http://exploreur1.labrute.fr **
3
cs_Exploreur Messages postés 4821 Date d'inscription lundi 11 novembre 2002 Statut Membre Dernière intervention 15 novembre 2016 15
30 janv. 2009 à 10:47
Salut,

Voici un bout de code (VB6), que tu pourra facilement retranscrire en .Net :

Private Sub Form_Load()


Dim YouString   As String
Dim NextString  As String
Dim iBoucle     As Integer


YouString = "Tata123titi"


For i = 1 To Len(YouString)
    NextString = Mid(YouString, i, 1)
    If IsNumeric(NextString) Then MsgBox "Numérique trouvé !!": Exit For
    ' ...
Next i


End Sub


A+
Exploreur

 Linux a un noyau, Windows un pépin
    ** http://exploreur1.labrute.fr **
0
cs_domxaline Messages postés 327 Date d'inscription jeudi 21 août 2008 Statut Membre Dernière intervention 10 mai 2012 2
30 janv. 2009 à 14:31
d'accord
si je veux compter combien de character dans ce string ?
merci d'avance
0
cs_Exploreur Messages postés 4821 Date d'inscription lundi 11 novembre 2002 Statut Membre Dernière intervention 15 novembre 2016 15
30 janv. 2009 à 15:03
Salut,

Bin tu rajoutes un compteur ma fois ^^ Compter les carractère ou le nombre de chiffre ?

A+
Exploreur

 Linux a un noyau, Windows un pépin
    ** http://exploreur1.labrute.fr **
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
cs_Exploreur Messages postés 4821 Date d'inscription lundi 11 novembre 2002 Statut Membre Dernière intervention 15 novembre 2016 15
30 janv. 2009 à 15:08
Re,

Private Sub Form_Load()


Dim YouString   As String
Dim NextString  As String
Dim iBoucle     As Integer
Dim iNbrChiffre As Integer
Dim iNbrChar    As Integer


YouString = "Tata123titi"


For i = 1 To Len(YouString)
    NextString = Mid(YouString, i, 1)
    If IsNumeric(NextString) Then
       MsgBox "Numérique trouvé !!": iNbrChiffre = iNbrChiffre + 1
    Else
       MsgBox "Carractère trouvé !!": iNbrChar = iNbrChar + 1
    End If
    ' ...
Next i




MsgBox "Nombres de numériques : " & iNbrChiffre
MsgBox "Nombres de carractères : " & iNbrChar




End Sub

Vla...c'est çà que tu souhaitais ? Tu peux faire une variante et reconstituer le numérique et la chaine de carractère aussi


A+
Exploreur

 Linux a un noyau, Windows un pépin
    ** http://exploreur1.labrute.fr **
0
cs_domxaline Messages postés 327 Date d'inscription jeudi 21 août 2008 Statut Membre Dernière intervention 10 mai 2012 2
30 janv. 2009 à 17:22
merci beaucoup
je vais l'essayer et je te dirai les nouvelles
0
cs_domxaline Messages postés 327 Date d'inscription jeudi 21 août 2008 Statut Membre Dernière intervention 10 mai 2012 2
3 févr. 2009 à 17:29
merci pour le prg
je l'ai essayé
le prg que tu m'a donné
donne un message chaque fois quand 'il rencontre un charcter ou un chiffre

moi je veux qu'il donne un message pour charcater et un message pour le chiffre
par ex :
6 charcater trouvé
et un autre  pour chiffre
 3 chiffres trouvés

merci d'avance
0
PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
3 févr. 2009 à 23:27
salut,

çà donne envie de t'aider si tu ne tiens pas compte de nos réponses

cf ici :
http://www.vbfrance.com/forum/sujet-AI-PB-AVEC-PRG-CHARS_1259219.aspx

voici une manière de faire :


    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        Dim SomeString As String = "George123"
        Dim Ascii As Int16
        For Each c As Char In SomeString
            'MessageBox.Show(c.ToString)
            Ascii = Convert.ToInt16(c)
            If Ascii > 47 AndAlso Ascii < 58 Then
                MessageBox.Show("Contient un chiffre")
                Exit For
            End If
        Next c
    End Sub
<!-- Coloration syntaxique vb/vba/vb.net : http://charles.racaud.free.fr/code-syntaxing/ -->
Coloration syntaxique vb/vba/vb.net 
0
cs_domxaline Messages postés 327 Date d'inscription jeudi 21 août 2008 Statut Membre Dernière intervention 10 mai 2012 2
4 févr. 2009 à 09:49
merci pour explorer,pb resoulu,ça marche

merci aussi pour PCPT
0
Rejoignez-nous