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
New Developer
bwitte
Posts: 21
Registered: ‎01-17-2009
My Device: Not Specified
Accepted Solution

String.length() in 4.6.0 and later

I am testing my programs in the 4.6.0 and later simulators and it seems that String.length() is reporting different values than is being returned in earlier versions.

 

For instance, I have a string that reports a length of 13 (the correct value) in the 4.0.x Simulator and a length of 14 in 4.6 and later Simulators. I've also tried moving the string to a char array and to a buffer with the same results.

 

A search here didn't turn this up... what could I be doing wrong? Is there such a fundamental bug in the newer JDEs/OS versions?

Please use plain text.
Developer
kingwhu
Posts: 42
Registered: ‎12-04-2008
My Device: Not Specified

Re: String.length() in 4.6.0 and later

Any blank or notation is added by mistake?
Please use plain text.
Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: String.length() in 4.6.0 and later

What value does your string hold ?

 

Provide us with sample values.

Please use plain text.
New Developer
bwitte
Posts: 21
Registered: ‎01-17-2009
My Device: Not Specified

Re: String.length() in 4.6.0 and later

[ Edited ]

Thanks for the replies and for forcing me to look more closely at the problem. 

 

The string is question is pulled from a list of menu items, obtained as shown in the below code.  When printing out the integer values of each of the characters in the string I find that there is a non-visible character with an integer value of  8206.  This appears to be a "lrm" character, and I'm sure I'm showing ignorance in not knowing what that is!

 

In any case, this does not occur in earlier instances of the simulator, as I mentioned.  Is this a bug introduced in the Menu / MenuItem objects?

 

I'm inclined to simply remove the non-visible characters, but my ignorance of things like double-byte character sets makes me wonder which characters I can safely remove.  All characters above a value of 256?  All above 8000?

 

 

Screen sc=UiApplication.getUiApplication().getActiveScreen();

Menu thisMenu = sc.getMenu(0);

// Code removed: Loop to find a particular menu item, with index if i

MenuItem menuItem = thisMenu.getItem(i);

Dialog.alert("DEBUG: menuItem is : '" + menuItem .toString() + "'");

Dialog.alert("DEBUG: menuItemLength is: " + String.valueOf(callMenuItem.toString().length()));

char currentChar = ' ';

for (int k=0; k < menuItem.toString().length(); k++) {
currentChar = menuItem.toString().charAt(k);
Dialog.alert("DEBUG: char " + String.valueOf(k) + " is: '" + currentChar + "'"
+ " ASCII value is: " + (int)menuItem.toString().charAt(k));
}

 

 

 

Message Edited by bwitte on 01-18-2009 07:27 AM
Please use plain text.
Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: String.length() in 4.6.0 and later

LRM is a control character. It is an acronym of "Left To Right".

 

Check the link below:

 

http://www.microsoft.com/middleeast/msdn/Control.aspx

Please use plain text.
New Developer
bwitte
Posts: 21
Registered: ‎01-17-2009
My Device: Not Specified

Re: String.length() in 4.6.0 and later

Thanks!  Funny that all my Googling didn't turn up that very useful MSFT link.

 

Anyone have thoughts on why these would have shown up in the newer JDE/Simulator versions?  Any thoughts on how to remove control/non-printable characters without removing useful characters?

 

Thanks again to all...

Please use plain text.
Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: String.length() in 4.6.0 and later

Perhaps the recent JDE versions support right-to-left languages along with left-to-right languages.

And these control characters help the device OS to handle strings.

 

From general point of view I do not recommend to use such techniques like menuItem.toString() to handle strings.

 

Declare a string array and build your menu titles from this array and use this array values for another purposes.

Please use plain text.
New Developer
bwitte
Posts: 21
Registered: ‎01-17-2009
My Device: Not Specified

Re: String.length() in 4.6.0 and later

Thanks very much for the thorough reply.

 

Forgive me, but not sure I follow your suggestion.  What I need to do is read in values from the menus on the screen; I do not create these menu items necessarily.  If I somehow build a string array by reading from the existing menu items, I'm guessing the string arrays would still contain the control characters. 

 

So, I'm wondering:

- What API calls might I make to grab the text from the menu items to pull them into an array?

- How would I avoid having the control characters appear in the array.

 

Again, thanks!

Please use plain text.
Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: String.length() in 4.6.0 and later

I advised to write strings from array to menu items.

 

Could you please describe the whole task where you need to read menu item titles.

 

What is the purpose of reading menu item titles?

 

It will allow me to give you more precise advice.

Please use plain text.
New Developer
bwitte
Posts: 21
Registered: ‎01-17-2009
My Device: Not Specified

Re: String.length() in 4.6.0 and later

In my code I need to obtain a list of the currenty available menu choices for the screen, and in certain cases parse out substrings from within the text displayed on a single menu item.

 

I may just find a way to ignore control characters, but any ideas you have would of course be helpful.

 

Thanks again.

Please use plain text.