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: 82
Registered: ‎12-16-2010
My Device: BlackBerry Storm 9950
Accepted Solution

Without RegEx how to?

find multiple instances of a String, for instance the word "src" inside of another string.

 

using IndexOf I can find the first instance  of "src" and use substrings, as suggested to me by simon in another thread closely related to this.

 

But this requires me to find multiple instances of a string inside of a larger string and insert substrings in an efficient way, without the capabilities of RegEx.

 

Any clues?

 

I can do it through If statements and just work my way towards the end of the string, but that seems like a lot more code than should be needed.

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

Re: Without RegEx how to?

a short search brought:

http://code.google.com/p/regexp-me/

 

user nmaddix also claims to have ported jakarta regex successfully here:

http://supportforums.blackberry.com/t5/Java-Development/Regular-expressions-on-blackberry/m-p/119069...

----------------------------------------------------------
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: 82
Registered: ‎12-16-2010
My Device: BlackBerry Storm 9950

Re: Without RegEx how to?

I have indeed tried to get that version of RegEx into my app, but both times it failed to compile.  The resources available for that supposed RegEx are close to nill, and nmaddox seems to be the only person who has ever successfully implemented it.

 

I'll send him a message. thank you for your help Simon, as always.

Developer
Posts: 133
Registered: ‎04-30-2010
My Device: Curve 8520
My Carrier: T-Mobile

Re: Without RegEx how to?

Make that nmaddox and me, then.  I have succesfully implemented jakarta regexp version 1.2 into my current project, without IIRC any code changes or compile problems.  And, there is a whole load of documentation in the download.

Highlighted
Developer
Posts: 114
Registered: ‎04-28-2010
My Device: Storm 9530
My Carrier: Telus

Re: Without RegEx how to?

Ping the expression to a server and make php do the work for you.

 

Only needs sockets and data connectivity instead of importing libraries.

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

Re: Without RegEx how to?

 

 


m-romanuik wrote:

Ping the expression to a server and make php do the work for you.

 

Only needs sockets and data connectivity instead of importing libraries.


just develop the application server-side, needs only the browser...

 

----------------------------------------------------------
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: 133
Registered: ‎04-30-2010
My Device: Curve 8520
My Carrier: T-Mobile

Re: Without RegEx how to?

Smiley Happy  @ Simon Hain

Developer
Posts: 82
Registered: ‎12-16-2010
My Device: BlackBerry Storm 9950

Re: Without RegEx how to?

Instead of getting that RegEx program that was suggested, I found this perfect alternative.

 

 

public static String replace(String _text, String _searchStr, String _replacementStr)
	{          
		//String buffer to store str         
		StringBuffer sb = new StringBuffer();           
		// Search for search        
		int searchStringPos = _text.indexOf(_searchStr);         
		int startPos = 0;        
		int searchStringLength = _searchStr.length();           
		// Iterate to add string 
		while (searchStringPos != -1) 
		{     
		sb.append(_text.substring(startPos, searchStringPos)).append(_replacementStr);    
		startPos = searchStringPos + searchStringLength; 
		searchStringPos = _text.indexOf(_searchStr, startPos);   
		}        
		// Create string     
		sb.append(_text.substring(startPos,_text.length()));   
		return sb.toString();     
	}

 So there ya go.