BlackBerry Forums Support Community

BlackBerry Forums Support Community (http://www.blackberryforums.com/index.php)
-   Developer Forum (http://www.blackberryforums.com/forumdisplay.php?f=15)
-   -   Read incoming sms without spaces (http://www.blackberryforums.com/showthread.php?t=260452)

Lukaszz 07-10-2012 03:38 PM

Read incoming sms without spaces
 
Hi,

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 =
(DatagramConnection)Connector.open("sms://");

for(;;) {

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

}

}catch (Exception me) { }
}



Thanks:smile:

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 02:01 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.