I have a field defined as a Text field. The field contains line breaks in it. I am printing this field to the screen and would like to replace the line breaks with HTML BR tags. Could someone help me with the code for this?

Alessandro A. Garbagnati

It's trivial, try this:

public String replaceString(String str, String sep, String rep) {
  StringBuffer retVal = new StringBuffer();
  int idx = 0;
  int jdx = str.indexOf(sep);
  while (jdx >= 0) {
    retVal.append(str.substring(idx, jdx));
    idx = jdx + sep.length();
    jdx = str.indexOf(sep, idx);
  return retVal.toString();

When you call it you can do something like:

String changed = replaceString(original, "original_string", "replace_string");

0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact