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
Posts: 235
Registered: ‎11-12-2008
My Device: Not Specified

{"aaaa","bbb","cc*%&vvc"};

String array={"aaaa","bbb","cc*%&vvc"};

how will remove the   *%   from the required above string.

Please help with a piece of code.

Thanks in advance.

Developer
Posts: 16,997
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: {"aaaa","bbb","cc*%&vvc"};

indexof and substring, both methods of the String class
----------------------------------------------------------
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
Developer
Posts: 235
Registered: ‎11-12-2008
My Device: Not Specified

Re: {"aaaa","bbb","cc*%&vvc"};

Can you provide a code for this..

Thanks in advance

Developer
Posts: 16,997
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: {"aaaa","bbb","cc*%&vvc"};

maybe you start with a "java in 21 days" book or something similar?
----------------------------------------------------------
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
Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: {"aaaa","bbb","cc*%&vvc"};

Your requirement isn't very well defined. For instance, this will work:

array[2] = "ccvvc";

but I suspect that you are looking to solve a more general problem. But what problem? If you want to remove all occurences of the characters '*', '%', or '&', then take a look at StringUtilities.removeChars. If you want to remove the character sequence "*%&", then using String.indexOf and substring as Simon suggests is the way to go. However, you need to define what should happen if you start with something like "cc*%&vvc*%&vvc" (which one(s) to remove?). Or even "cc**%&%&vvc" (there's only one occurrence of "*%&", but after it's removed, all of a sudden there's another one!)




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: {"aaaa","bbb","cc*%&vvc"};

I think Simon's point is valid.  This is a Java question and would perhaps be better directed at a forum that is specifically for Java.  In addition, if someone can't create a piece of Java code that uses substring and indexOf, then perhaps a course is needed.

Highlighted
Developer
Posts: 587
Registered: ‎01-19-2010
My Device: BOLD 9700 OS5.0.0.x on Rogers Canada
My Carrier: Rogers

Re: {"aaaa","bbb","cc*%&vvc"};

I'm afraid I don't have any links for Java newbies at the moment. But if you Google "Introduction to Java" I'm sure there are a few good online tutorials out there (Who reads these days? Smiley Tongue)

 

Good luck,

~Dom

 

PS - String array={"aaaa","bbb","cc*%&vvc"}; is improper syntax --

 

You would get a compiler error because you forgot to include the square brackets ('[' and ']') to indicate that it is an array. Try:

 

 

String [] array = { "aaaa", "bbb", "cc*%&vvc" };

 

 

Then, to remove '*%&'...

 

 

String s = array [2];
String s2 = *%&;

s = s.substring (0, s.indexOf (s2)) //"cc"
s += s.substring (s.indexOf (s2) + s2.Length, s.Length () - (s.indexOf (s2) + s2.Length ())); //"cc" + "vvc"

array [2] = s;

 

 

That's a pretty ugly snippet, but basically what it's doing is removing the unwanted segment by creating a new string which is the first segment, "cc", plus the end segment, "vvc".

 

 

----------------------------------------------------------------------------
chown -R us ./base
~J!NX