Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Parse string and select specific text in the string
v-2muda
<div>How to parse strings and selecting specific texts in strings in BIRT?</div>
<div> </div>
<div>I have to show only the text which is in [] with the following rules</div>
<div> </div>
<div>Rule:</div>
<div>1.Only the text in [] at the beginning and discard anything which is after </div>
<div> </div>
<div>2.If the text in [] is not found at the beginning but somewhere in the string replace the o/p to blank </div>
<div> </div>
<div>[ABC] HELLO WORLD [xyz] This is new</div>
<div> </div>
<div>Expected o/p:</div>
<div> </div>
<div>
</div>
<div>[ABC]</div>
<div> </div>
<div> </div>
<div> </div>
<div>HELLO WORLD [xyz] This is new</div>
<div> </div>
<div>Expected o/p:</div>
<div> </div>
<div>
</div>
<div>blank</div>
Find more posts tagged with
Comments
pricher
<p>Hi,</p>
<p> </p>
<p>You can use JavaScript String methods to parse your string. For example, if "Text" is the originating column in your data set, you can create a computed column "StrippedText" with the following expression:</p>
<pre class="_prettyXprint _lang-">
out = "";
if(row["Text"].substr(0,1) == "[") {
end = row["Text"].indexOf("]");
out = row["Text"].substring(0, end + 1);
}
out;
</pre>
<p>Hope this helps,</p>
<p> </p>
<p>P.</p>
v-2muda
<blockquote class="ipsBlockquote" data-author="pricher" data-cid="147563" data-time="1494342445">
<div>
<p>Hi,</p>
<p> </p>
<p>You can use JavaScript String methods to parse your string. For example, if "Text" is the originating column in your data set, you can create a computed column "StrippedText" with the following expression:</p>
<pre class="_prettyXprint _lang-">
out = "";
if(row["Text"].substr(0,1) == "[") {
end = row["Text"].indexOf("]");
out = row["Text"].substring(0, end + 1);
}
out;
</pre>
<p>Hope this helps,</p>
<p> </p>
<p>P.</p>
</div>
</blockquote>
<p> </p>
<p>Thanks this works .</p>
<p> </p>
<p>How can I strip off the [ ] from final string?</p>
<p> </p>
<p>Current o/p:</p>
<p> </p>
<p><span style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">[ABC]</span></p>
<p> </p>
<p><span style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">Expected o/p</span></p>
<p> </p>
<p><span style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">ABC</span></p>
v-2muda
<blockquote class="ipsBlockquote" data-author="v-2muda" data-cid="147564" data-time="1494345181">
<div>
<p>Thanks this works .</p>
<p> </p>
<p>How can I strip off the [ ] from final string?</p>
<p> </p>
<p>Current o/p:</p>
<p> </p>
<p><span style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">[ABC]</span></p>
<p> </p>
<p><span style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">Expected o/p</span></p>
<p> </p>
<p><span style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">ABC</span></p>
</div>
</blockquote>
<p> </p>
<p>I figured it out</p>
<p> </p>
<div>out1=out.replace("[","");</div>
<div>out2=out1.replace("]","")</div>
pricher
<p>Actually, you should simply change the arguments of the substring method, like this:</p>
<pre class="_prettyXprint _lang-">
out = "";
if(row["Text"].substr(0,1) == "[") {
end = row["Text"].indexOf("]");
out = row["Text"].substring(1, end);
}
out;
</pre>