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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
New Developer
myquestion
Posts: 186
Registered: ‎11-12-2008

{"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.

Please use plain text.
Developer
simon_hain
Posts: 13,774
Registered: ‎07-29-2008
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
Please use plain text.
New Developer
myquestion
Posts: 186
Registered: ‎11-12-2008

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

Can you provide a code for this..

Thanks in advance

Please use plain text.
Developer
simon_hain
Posts: 13,774
Registered: ‎07-29-2008
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
Please use plain text.
Developer
Ted_Hopp
Posts: 1,304
Registered: ‎01-21-2009

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.
Please use plain text.
Developer
peter_strange
Posts: 17,663
Registered: ‎07-14-2008

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.

Please use plain text.
Developer
DAquilina
Posts: 587
Registered: ‎01-19-2010
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? :smileytongue:)

 

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
Please use plain text.