Home
Analytics
String.replace and replaceFirst in BIRT
isl01jbe
Hi All,
I am trying to replace parts of a string. More exactly, I am trying to replace parts of my sql query string using this.queryText = this.queryText.replace("[Bobs your uncle]","Yes he is");
The trouble is that "replace" replaces all occurrences of "[Bobs your uncle]". I only want to remove the first occurrence. In order to do this, I tried using replaceFirst instead. This didn't work as the string is then suddenly interpreted as a regular expression and no match with my string is found.
So, a few alternatives remain:
1. Make replace only replace first occurence
2. Make replaceFirst use string literals instead of interpreting them as regex
3. Escape my string before using replaceFirst.
Any help is appreciated.
Best regards
Jonas
Find more posts tagged with
Comments
mwilliams
Can you recreate your issue with the sample database, so I can run the report? I tried using replaceFirst and it works without issue.
isl01jbe
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="97353" data-time="1331075013" data-date="06 March 2012 - 04:03 PM"><p>
Can you recreate your issue with the sample database, so I can run the report? I tried using replaceFirst and it works without issue.<br /></p></blockquote>
<br />
Hi,<br />
<br />
Attached is a simple report showing an example<br />
<br />
Best regards<br />
<br />
Jonas
mwilliams
It works correctly if you don't have the ':' or '[]' in there. Like, if you just use --paramTest, it works. Do you have to use the special characters? They seem to be what's causing the issue.