1

I am making an App with the help of which I can get an ArrayList of all the Text messages. I had no problem for achieving that but when I am sending it to default SMS application of Android device, I see the text surrounding by "[]". But I don't want that brackets.

For Eg.: My Inbox has a text "Hello World", but I am getting string displaying "[Hello World]". I want the exact message that is being displayed in my Inbox. So what should i do to remove extra "[]" from my string.

Please help me on that. Thanks in advance

Name is Nilay
  • 2,743
  • 4
  • 35
  • 77

1 Answers1

1

If you are trying to send the whole ArrayList with toString() and it's displaying the brackets you can try to rebuild the string:

String message = "";
    for(int i=0; i<array.size(); i++){
        message += array.get(i) + ", ";
    }

Where ", " can be your delimiter. But I'm not sure this is what you want, can you provide more info in the description?

EDIT: Try

String message="[Hello World]";
        message.substring(1,message.length()-1);
  • I have edited my post. Hope it help now. Kindly reply me with answer. Thanks – Name is Nilay Jul 11 '12 at 11:56
  • @NilayOnAndroid I have updated the answer. Try the code after edit. –  Jul 11 '12 at 12:04
  • @Alexandru-I already tried that but instead I am getting output as "[ello Worl]". So the "[]" persists !!! – Name is Nilay Jul 11 '12 at 12:16
  • No...It doesn't solve my problem. I think Brackets are added by android itself, after we store the message into list...!!! – Name is Nilay Jul 11 '12 at 12:23
  • 1
    Can you obtain the final string before you send it? If you have a plain string object that has brackets there is no problem removing them. I'm not sure what you are doing there. Post some code. –  Jul 11 '12 at 12:25
  • Yup. I obtained the final string and then trimmed it from both sides. Thanks 4 support. That really helped !! – Name is Nilay Jul 11 '12 at 12:28