Question

I want to extract only the exact character in a CharSequence when I know the position (or key) of the character in it!

For eg: In the CharSequence "HELLO" I want to Extract the letter in the position 2 which is "E" in this case . How can I do that?

TO BE MORE SPECIFIC: I am building an Android application where I am using the TextWatcher to obtain the text entered by people in the TextEdit field as follows.

    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

        }
    });

My Question is commented within the code as well.

Thanks for any help anyone can provide. Adit

Was it helpful?

Solution

Use the charAt() method on CharSequence.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top