1 package SnowMailClient.utils; 2 3 public class StringUtils 4 { 5 6 public StringUtils() 7 { 8 9 } 11 12 13 16 public static boolean startsWithIgnoresCaseAndBlanks(String text, String start) 17 { 18 for(int i=0; i<text.length()-start.length(); i++) 20 { 21 if( text.substring(i, i+start.length()).equalsIgnoreCase(start)) return true; 23 24 if( text.charAt(i)==' ' || text.charAt(i)=='\r' || text.charAt(i)=='\n' 25 || text.charAt(i)=='\t') continue; 26 break; 27 } 28 return false; 29 } 30 31 34 public static int indexOfStartTagIgnoreCase(String text, String tagName) 35 { 36 for(int i=0; i<text.length()-tagName.length(); i++) 37 { 38 if(text.charAt(i)=='<') 39 { 40 String tt = text.substring(i+1,i+1+tagName.length()); 41 if(tt.compareToIgnoreCase(tagName)==0) return i+1; 43 } 44 } 45 return -1; 46 } 47 48 51 public static int indexOfEndTagIgnoreCase(String text, String tagName) 52 { 53 for(int i=tagName.length(); i<text.length(); i++) 54 { 55 if(text.charAt(i)=='>') 56 { 57 String tt = text.substring(i-tagName.length(), i); 58 if(tt.compareToIgnoreCase(tagName)==0) return i; 60 } 61 } 62 return -1; 63 } 64 65 66 public static String toString(byte[] array) 67 { 68 if(array==null) return "null"; 69 if(array.length==0) return "{}"; 70 StringBuffer sb = new StringBuffer ("{"); 71 for(byte b:array) 72 { 73 sb.append(""+b); 74 sb.append(", "); 75 76 } 77 return sb.substring(0, sb.length()-2)+"}"; 78 } 79 80 public static void main(String [] a) 81 { 82 System.out.println(indexOfStartTagIgnoreCase("<br> \r\t\n <br><p> <html>", "bR")); 83 } 84 85 } | Popular Tags |