/** * Chop i characters off the end of a string. * This method assumes that any EOL characters in String s * and the platform EOL will be the same. * A 2 character EOL will count as 1 character. * * @param string String to chop. * @param i Number of characters to chop. * @return String with processed answer. */ public static String chop(String s, int i) { return chop(s, i, EOL); }
/** * Chop i characters off the end of a string. * This method assumes that any EOL characters in String s * and the platform EOL will be the same. * A 2 character EOL will count as 1 character. * * @param s String to chop. * @param i Number of characters to chop. * @return String with processed answer. */ public static String chop(String s, int i) { return chop(s, i, EOL); }
/** * Chop i characters off the end of a string. * This method assumes that any EOL characters in String s * and the platform EOL will be the same. * A 2 character EOL will count as 1 character. * * @param s String to chop. * @param i Number of characters to chop. * @return String with processed answer. */ public static String chop(String s, int i) { return chop(s, i, EOL); }
public void runTest() { /* * some StringUtils tests */ String eol = "XY"; String arg = "XY"; String res = StringUtils.chop(arg, 1, eol ); assertTrue( "Test 1", res.equals("") ); arg = "X"; res = StringUtils.chop( arg, 1, eol ); assertTrue( "Test 2", res.equals("") ); arg = "ZXY"; res = StringUtils.chop( arg, 1, eol ); assertTrue( "Test 3", res.equals("Z") ); arg = "Hello!"; res = StringUtils.chop( arg, 2, eol ); assertTrue( "Test 4", res.equals("Hell")); }
/** * Hacky method to figure out the relative path * that we are currently in. This is good for getting * the relative path for images and anchor's. */ private String getRelativePath(String file) { if (file == null || file.length()==0) return ""; StringTokenizer st = new StringTokenizer(file, "/\\"); // needs to be -1 cause ST returns 1 even if there are no matches. huh? int slashCount = st.countTokens() - 1; StringBuffer sb = new StringBuffer(); for (int i=0;i<slashCount ;i++ ) { sb.append ("../"); } if (sb.toString().length() > 0) { return StringUtils.chop(sb.toString(), 1); } return "."; }
/** * Hacky method to figure out the relative path * that we are currently in. This is good for getting * the relative path for images and anchor's. */ private String getRelativePath(String file) { if (file == null || file.length()==0) return ""; StringTokenizer st = new StringTokenizer(file, "/\\"); // needs to be -1 cause ST returns 1 even if there are no matches. huh? int slashCount = st.countTokens() - 1; StringBuffer sb = new StringBuffer(); for (int i=0;i<slashCount ;i++ ) { sb.append ("../"); } if (sb.toString().length() > 0) { return StringUtils.chop(sb.toString(), 1); } return "."; }
/** * Hacky method to figure out the relative path * that we are currently in. This is good for getting * the relative path for images and anchor's. */ private String getRelativePath(String file) { if (file == null || file.length()==0) return ""; StringTokenizer st = new StringTokenizer(file, "/\\"); // needs to be -1 cause ST returns 1 even if there are no matches. huh? int slashCount = st.countTokens() - 1; StringBuffer sb = new StringBuffer(); for (int i=0;i<slashCount ;i++ ) { sb.append ("../"); } if (sb.toString().length() > 0) { return StringUtils.chop(sb.toString(), 1); } else { return "."; } }