2012-12-24 2 views
2

Je veux extraire seulement le caractère exact dans un CharSequence quand je connais la position (ou la clé) du caractère dedans!Comment obtenir un caractère EXACT dans une séquence CharSequence?

For eg: In the CharSequence "HELLO" I want to Extract the letter in the position 2 which is "E" in this case. Comment puis-je faire cela?

Plus précisément: Je construis une application Android où j'utilise le TextWatcher pour obtenir le texte saisi par des personnes dans le domaine TextEdit comme suit.

EditText KeyLogEditText = (EditText) findViewById(R.id.editTextforKeyLog); 
    KeyLogEditText.addTextChangedListener(new TextWatcher() { 

     @Override 
     public void onTextChanged(CharSequence s, int start, int before, int count) { 
      // Here is where I need help!! 
      // I have the "start" and "before" keys I have the position of the character inserted 
      // I need to obtain the EXACT character from the CharSequence "s", How do I Do that?     

     } 

     @Override 
     public void beforeTextChanged(CharSequence s, int start, int count, 
       int after) { 
      // TODO Auto-generated method stub 

     } 

     @Override 
     public void afterTextChanged(Editable s) { 
      // TODO Auto-generated method stub 

     } 
    }); 

Ma question est commentée dans le code.

Merci de votre aide. Adit

Répondre

7

Utilisez the charAt() method sur CharSequence.

+2

Vous avez probablement besoin de 'longueur()' aussi. Indexation à base zéro de la séquence, donc E dans HELLO est charAt (1). –

Questions connexes