Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
simon_hain
Posts: 16,010
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Can a string look identical but fail .equals or .startsWith?

i use a similar approach to Jared, just a bit tidied up.

first, the number delivered from the phone usually (or always?) contains a '+'.

 

 

int plusIndex = number.indexOf('+');
if (plusIndex > -1){
	number = number.substring(plusIndex);
}

 

you can check the rest by using Character.isDigit

 

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
QuiteSimple
Posts: 1,452
Registered: ‎11-06-2009
My Device: Torch 9810
My Carrier: WiFi

Re: Can a string look identical but fail .equals or .startsWith?

If I recall it correct, the code belowe returns some unreadable byte in front of the phone number. It was introduced in OS 4.6 for sure (in older OS versions it was just fine), I din't check it for OS above 4.6.

 

 


_______________________________________________________________________
        String m_phoneNumberCalled; 
            PhoneCall pc = Phone.getActiveCall();
            String displayNumberWithSpaces = pc.getDisplayPhoneNumber();


 



"When you become a level 3 developer, you learn to communicate over the ether. I'm told that level 5 developers are ascend into a higher level of existence beyond the physical realm." gord888 @ crackberry
Please use plain text.
Developer
justindutoit
Posts: 401
Registered: ‎05-31-2009
My Device: Not Specified

Re: Can a string look identical but fail .equals or .startsWith?

Hey. Will be able to test and mark solved shortly, tks for help

 

J

Please use plain text.
Developer
justindutoit
Posts: 401
Registered: ‎05-31-2009
My Device: Not Specified

Re: Can a string look identical but fail .equals or .startsWith?

OK, it's tested now. The phone number you get with the following code

 

PhoneCall pc = Phone.getActiveCall();
String displayNumber = pc.getDisplayPhoneNumber();

 

 

has 'hidden' characters in front, in my case two hex 200e chars. They can be stripped with code like the following: (BTW when the below code is run, the ctrl-click shows as bytes anyway).

 

                PhoneCall pc = Phone.getActiveCall();
                String thestring = pc.getDisplayPhoneNumber();

                char[] chars = new char[thestring.length()];
                thestring.getChars(0, thestring.length(), chars, 0);
                
                String s = "";
                int i = 0;
                
                while (!Character.isDigit(chars[i]) && chars[i] != '+') i++;
                while (i < chars.length) { s = s + chars[i]; i++; }
                

 

 

Please use plain text.
Developer
justindutoit
Posts: 401
Registered: ‎05-31-2009
My Device: Not Specified

Re: Can a string look identical but fail .equals or .startsWith?

Hey, one thing- is a phone number universally + or digits? (except for the 'invisible' chars). I'm stripping anything at the beginning that's neither + nor 0-9

 

Tks

J

Please use plain text.
Developer
Ted_Hopp
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: Can a string look identical but fail .equals or .startsWith?

There are lots of conventions for representing telephone numbers, including all the cute words people can make out of the letters assigned to digits 2-9. I think that for international dialing, they are all equivalent to a string of digits. Internally in a particular organization, sometimes * and # are also part of the dialing sequence. Same thing goes for extra services a phone company may offer (as in *69). Dialing sequences through modems, etc., sometimes use a comma or other punctuation to represent a command to pause or wait for a change in the line state.

 

I don't know if that helps. Perhaps if you explained something about your application, someone could provide a more specific answer.

 

You'll also be more likely to get an answer if you start a new thread. This one is already marked as solved. Plus the topic seems to have strayed quite a bit from the posted subject.




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Please use plain text.