IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Java Discussion :

Problème lors de l'appel d'une fonction


Sujet :

Java

  1. #1
    Membre régulier
    Femme Profil pro
    étudiante chercheuse
    Inscrit en
    Septembre 2013
    Messages
    274
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : étudiante chercheuse
    Secteur : Enseignement

    Informations forums :
    Inscription : Septembre 2013
    Messages : 274
    Points : 101
    Points
    101
    Par défaut Problème lors de l'appel d'une fonction
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    public static  int getIndexTFromString (String Nom_T)
    	{
    		int  i=-1;
    		if  (Nom_T.contains("TCreation")) 
    		{
    			String sub ="" ; 
    		int posT = Nom_T.indexOf("T") ; 
    		int posC = Nom_T.indexOf("C") ; 
    		sub =   Nom_T.substring(posT+1,posC) ;
    		  return i = Integer.parseInt(sub) ; 
    		} 
    	 if  (Nom_T.contains("TIncremtPeriod")) 
    		{
    			String sub ="" ; 
    		int posT = Nom_T.indexOf("T") ; 
    		int posI = Nom_T.indexOf("I") ; 
    		sub =   Nom_T.substring(posT+1,posI) ;
    		 return  i = Integer.parseInt(sub) ; 
    		} 
    	 if  (Nom_T.contains("TReset")) 
    		{
    			String sub ="" ; 
    		int posT = Nom_T.indexOf("T") ; 
    		int posR = Nom_T.indexOf("R") ; 
     
     
    		sub =   Nom_T.substring(posT+1,posR) ;
     
    		 return  i = Integer.parseInt(sub) ; 
    		} 
    		 if  (Nom_T.contains("TActivation")) 
    		{
    			String sub ="" ; 
    		int posT = Nom_T.indexOf("T") ; 
    		int posA = Nom_T.indexOf("A") ; 
     
     
    		sub =   Nom_T.substring(posT+1,posA) ;
     
    		 return  i = Integer.parseInt(sub) ; 
    		} 
    		if  (Nom_T.contains("TExecution")) 
    		{
    			String sub ="" ; 
    		int posT = Nom_T.indexOf("T") ; 
    		int posE = Nom_T.indexOf("E") ; 
     
     
    		sub =   Nom_T.substring(posT+1,posE) ;
     
    		 return  i = Integer.parseInt(sub) ; 
    		} 
    		if  (Nom_T.contains("TIncrementing")) 
    		{
    			String sub ="" ; 
    		int posT = Nom_T.indexOf("T") ; 
    		int posI = Nom_T.indexOf("I") ; 
     
     
    		sub =   Nom_T.substring(posT+1,posI) ;
     
    		 return  i = Integer.parseInt(sub) ; 
    		} 
    		if  (Nom_T.contains("TReceiving")) 
    		{
    			String sub ="" ; 
    		int posT = Nom_T.indexOf("T") ; 
    		int posR = Nom_T.indexOf("R") ; 
     
     
    		sub =   Nom_T.substring(posT+1,posR) ;
     
    		 return  i = Integer.parseInt(sub) ; 
    		} 
    		 if  (Nom_T.contains("TReleasing")) 
    		{
    			String sub ="" ; 
    		int posT = Nom_T.indexOf("T") ; 
    		int posR = Nom_T.indexOf("R") ; 
     
     
    		sub =   Nom_T.substring(posT+1,posR) ;
     
    		 return  i = Integer.parseInt(sub) ; 
    		} 
    		 if  (Nom_T.contains("TSending")) 
    		{
    			String sub ="" ; 
    		int posT = Nom_T.indexOf("T") ; 
    		int posS = Nom_T.indexOf("S") ; 
     
     
    		sub =   Nom_T.substring(posT+1,posS) ;
     
    		 return  i = Integer.parseInt(sub) ; 
    		}
     
    		return i ;
    	}

    cette fontion permet de dégager un entier à partir d'un String
    lorsque j'appelle dans le programme principale main System.out.print("#"+getIndexTFromString ("T11Releasing"));
    ça donne toujour la valeur d'erreur -1
    aidez moi s'il vous plait

  2. #2
    Modérateur
    Avatar de wax78
    Homme Profil pro
    Chef programmeur
    Inscrit en
    Août 2006
    Messages
    4 084
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : Belgique

    Informations professionnelles :
    Activité : Chef programmeur
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2006
    Messages : 4 084
    Points : 7 995
    Points
    7 995
    Par défaut
    Ouais, ton code la il ne marchera jamais et retournera toujours -1 car tu lui rentres "T11Releasing" avec ensuite un test sur

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Nom_T.contains("TReleasing")
    et donc forcement TReleasing n'est pas T11Releasing.

    Tu pourrais peut être remplacer cela en utilisant une expression reguliere qui permettre de a partir d'un string recuperer uniquement "les chiffres".

  3. #3
    Membre régulier
    Femme Profil pro
    étudiante chercheuse
    Inscrit en
    Septembre 2013
    Messages
    274
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : étudiante chercheuse
    Secteur : Enseignement

    Informations forums :
    Inscription : Septembre 2013
    Messages : 274
    Points : 101
    Points
    101
    Par défaut
    déjà c'est ce que ce code fait ,il dégage à partir d'une chaîne de caractère le Chiffre à l' intérieur si il existe . lit le code attentivement tu va remarquer que je traite la chaîne, bein je sais que le chiffre va être entre la lettre T et le caractère qui suit (j'ai déjà utilisé ce code avant et il marche bien ) ici je sais pas c'est quoi la problème .

  4. #4
    Membre régulier
    Femme Profil pro
    étudiante chercheuse
    Inscrit en
    Septembre 2013
    Messages
    274
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : étudiante chercheuse
    Secteur : Enseignement

    Informations forums :
    Inscription : Septembre 2013
    Messages : 274
    Points : 101
    Points
    101
    Par défaut
    c'est bon ,mon problème résolu merci

  5. #5
    Modérateur
    Avatar de wax78
    Homme Profil pro
    Chef programmeur
    Inscrit en
    Août 2006
    Messages
    4 084
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : Belgique

    Informations professionnelles :
    Activité : Chef programmeur
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2006
    Messages : 4 084
    Points : 7 995
    Points
    7 995
    Par défaut
    Citation Envoyé par FATENMRABET Voir le message
    lit le code attentivement tu va remarquer que je traite la chaîne
    Mouais, je sais très bien lire ton code. La c'est l'hopital qui se fout de la charité la

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [XL-2000] Problème lors de l'appel d'une fonction
    Par juju05 dans le forum Macros et VBA Excel
    Réponses: 6
    Dernier message: 17/02/2014, 13h18
  2. Problème lors de l'appel d'une fonction Tsql
    Par mobscene dans le forum MS SQL Server
    Réponses: 3
    Dernier message: 23/07/2007, 15h56
  3. [MySQL] problème lors de l'appel d'une fonction
    Par jexl dans le forum PHP & Base de données
    Réponses: 5
    Dernier message: 27/06/2007, 09h53
  4. Réponses: 3
    Dernier message: 01/05/2007, 16h07
  5. [POO] Problème lors de l'appel d'une propriété d'un objet.
    Par akecoocoo dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 24/08/2005, 08h51

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo