BlackBerry Forums Support Community

BlackBerry Forums Support Community (
-   Developer Forum (
-   -   Read incoming sms without spaces (

Lukaszz 07-10-2012 03:38 PM

Read incoming sms without spaces

The following code reads an incoming sms then prints the body of the message. How do I get the app to print out the message without any spaces inbetween?

For example: The incoming sms reads "Here I am", so "Here I am" is printed out, but I want the app to print out "HereIam".

How can I do this? Any help would be most appreciated.

Here is my code:

public void run() {

try {

DatagramConnection _dc =

for(;;) {

Datagram d = _dc.newDatagram(_dc.getMaximumLength());
byte[] bytes = d.getData();
String address = d.getAddress();
String msg = new String(bytes);


}catch (Exception me) { }


Dougsg38p 07-11-2012 12:56 PM

Re: Read incoming sms without spaces
I would create a new StringBuffer, then loop though the characters in the original string, appending each non-blank (!= '32') char to the StringBuffer.

Lukaszz 07-11-2012 04:11 PM

Re: Read incoming sms without spaces
Can you please provide me some code or a link that I can go to to read up on how to go about doing that?

Dougsg38p 07-12-2012 10:58 AM

Re: Read incoming sms without spaces
You can't iterate though the chars of a string?

Do you understand the concept of a for{} loop?

- create the string buffer
- get the length of the original message
- enter the for{} look, indexing through the chars of the string until you hit the end
- for each char that is not a ' ' (32), append the char to the string buffer.

All times are GMT -5. The time now is 04:23 AM.

Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2015, Jelsoft Enterprises Ltd.