1 24 25 package gnu.jpdf; 26 27 35 public class PDFStringHelper 36 { 37 43 public static String makePDFString(String s) { 44 if(s.indexOf("(")>-1) 45 s = replace(s,"(","\\("); 46 47 if(s.indexOf(")")>-1) 48 s = replace(s,")","\\)"); 49 50 return "("+s+")"; 51 } 52 53 60 private static String replace(String source, 61 String removeThis, 62 String replaceWith) { 63 StringBuffer b = new StringBuffer (); 64 int p = 0, c=0; 65 66 while(c>-1) { 67 if((c = source.indexOf(removeThis,p)) > -1) { 68 b.append(source.substring(p,c)); 69 b.append(replaceWith); 70 p=c+1; 71 } 72 } 73 74 if(p<source.length()) 76 b.append(source.substring(p)); 77 78 return b.toString(); 79 } 80 } | Popular Tags |