0

I am getting the title from an RSS feed and displaying it using an array adapter. How can I replace a special character with an empty space? Can anyone help on this?

ArrayAdapter<String> itemList = new ArrayAdapter<String>(this, R.layout.cricketlist, item);
3
  • What is your special character? Commented Jun 23, 2012 at 8:59
  • This is my special character &quot; Commented Jun 23, 2012 at 9:01
  • @sravanthi you don't need to specify android in question title as this is handled by the tag Commented Jun 23, 2012 at 9:49

3 Answers 3

2

Assuming str is your String.

str = str.replace("&quot;", " ");
Sign up to request clarification or add additional context in comments.

Comments

0

Try String.replaceAll(String regex, String replacement) and String.replace(char oldChar, char newChar) for relpacing chars from string

Comments

0

Try this:

 str = str.replaceAll("[^a-zA-Z 0-9]+"," ")

Also

public string deleteSpecialChar(string text)
        {
            StringBuilder sb = new StringBuilder();
            var lastWasInvalid = false;
            for(int i=0;i<text.length();i++)
            {
                if (Character.isLetterOrDigit(text.charAt(i)))
                {
                    sb.Append(c);
                    lastWasInvalid = false;
                }
                else
                {
                    if (!lastWasInvalid)
                        sb.Append(" ");
                    lastWasInvalid = true;
                }
            }

            return sb.ToString().Trim();

        }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.