2012-12-24 12 views
2

我只想提取CharSequence中的確切字符,當我知道字符在其中的位置(或鍵)時!如何獲取CharSequence中的精確字符?

For eg: In the CharSequence "HELLO" I want to Extract the letter in the position 2 which is "E" in this case我該怎麼做?

更具體: 我在哪裏我使用的是TextWatcher獲得如下的文字編輯領域的人輸入的文本建立一個Android應用程序。

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 

     } 
    }); 

我的問題也在代碼中進行了評論。

感謝任何人都可以提供的幫助。 Adit

回答

7

CharSequence上使用the charAt() method

+2

也可能需要'length()'。序列的基於零的索引,所以HELLO中的E是charAt(1)。 –