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
ankur_siwach
Posts: 142
Registered: ‎09-28-2012
My Device: Blackberry Developer
My Carrier: Aircel

how to replace special character

Hello,

 

i have some text file which contain some special chatacters appers like encoded characters, i want to replace them but they are not replacing, i am able to replace all others characters except that special encoded characters,

 

how can i replace them.

 

below is that special character..

 

actualText.replace(' ’ ', ' ' ');

 

please help me..


----------------------------------------------------------
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.
Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: how to replace special character

Sorry don't understand this question.

 

What character can you not replace?  Can you give us the Unicode number associated with it?

 

Can you not say something like

char oldChar = '/u...';

char newChar = '/...';

actualText.replace(oldChar,newChar);

 

I suspect in fact there is an underlying problem here, in that you have obtained some data from the Server and are struggling to process itRemember it is probably UTF-8 encoded, and that if you are using XML, the values will have been converted so that they can be placed in a XML stringReplacing characters will probably not help in these cases

Please use plain text.
Developer
ankur_siwach
Posts: 142
Registered: ‎09-28-2012
My Device: Blackberry Developer
My Carrier: Aircel

Re: how to replace special character

i have already highlighted  that special character in the replace function parameter my old char parameter contain that character , acutally i have copied some text from the internet which appear like a '(comma) but when we display that inside the label field its looks like a rectangle box...

 

on my new hubby’s birthday

 

here ’s the character...


----------------------------------------------------------
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.
Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: how to replace special character

[ Edited ]

Add code to convert the String to a char array, debug your application, view the String in the debugger and tell us what the character actually is.  Possibly a character array will enable you to see the actual character better. 

 

Sample code:

     String testString = "test stiing2";
     char [] testChars = testString.toCharArray();

 

Now look at the testChars array, find the characters that is causing the problem, and tell us what it is. 

 

You said you copied it from the internet, how did you do get the data?  More specifically, how do you convert the bytes you get from the internet to a String for display?  What encoding do you use in your conversion? 

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: how to replace special character

To find out exactly what the character is, you might have to change the Primitive display.  In Debug perspective, look for the Variables window, and use the mneu form there to get the Java Preferences:

 

Change primiative Display to display hexadecimal values.

 

See attached screen shots. 

 

Note that the characters are also displayed with the /u form. 

Please use plain text.
Developer
ankur_siwach
Posts: 142
Registered: ‎09-28-2012
My Device: Blackberry Developer
My Carrier: Aircel

Re: how to replace special character

actually i copied data from the internet and store it into the text file ,

and i am reading that text file using InputStream and than converting that data into string...


----------------------------------------------------------
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.
Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: how to replace special character

"actually i copied data from the internet and store it into the text file ,

and i am reading that text file using InputStream and than converting that data into string..."

 

This means you have more opportunities to incorrectly process the character encoding. 

 

I have updated my previous post to make it clearer.  So can you please follow these instructions to debug the data so that we and you can figure out what the character actually is. 

 

Can you also tell us the character encoding used by the data you have downloaded from the internet?  All character data sent as bytes has an encoding, whether deliberate or not, so if you don't know it, this is something you need to find out. 

Please use plain text.