I have a requirement. I have a string which has a value for eg:
<p>We are pleased <a href="http://www.anc.com/content/cy-tech/global/en/cq5-reference-materials.s_cid_123.html">to present the new product type</a>. This new product type is the best thing since sliced bread. We are pleased to present the new product type. This new product <a href="mailto:abc@gmail.com">type is the best</a> thing since sliced bread.</p>
The above text will be stored as a single string value. I need to append certain parameters to the hrefs after checking the criteria. Let me know how to extract only the href and append the parameter and display the string without damage (FYI : the string is the value entered through RTE - rich text editor)
Tried this approach but without success.
String tmpStr = "href=\"http://www.abc.com\">design";
StringBuffer tmpStrBuff = new StringBuffer();
String[] tmpStrSpt = tmpStr.split(">");
if (tmpStrSpt[0].contains("abc.com")) {
String[] tmpStrSpt1 = tmpStrSpt[0].split("\"");
tmpStrBuff.append(tmpStrSpt1[0]);
if (tmpStrSpt1[1].contains("?")) {
tmpStrBuff.append("\"" + tmpStrSpt1[1] + "&s_cid=abcd_xyz\">");
} else {
tmpStrBuff.append("\"" + tmpStrSpt1[1] + "?s_cid=abcd_xyz\">");
}
tmpStrBuff.append(tmpStrSpt[1]);
tmpStrBuff.append("</a>");
System.out.println(" <p>tmpStr1:::: " + tmpStrBuff.toString() + "</p>");
}
the other approach used is :
String[] tmpTxtArr = text.split("\\s+");
StringBuffer tmpStrBuff = new StringBuffer();
for (String tmpTxt : tmpTxtArr) {
descTxt += (tmpTxt.contains("abc.com") && !tmpTxt.contains("?")) ? tmpTxt
.replace("\">", "?s_cid=" + trackingCode + "\">" + " ")
: tmpTxt + " ";
}