测试String字符串各种基本方法的使用[回钦波个人总结]

package qinbo.teststring;

public class TestString {
 //ADD_START-20101209 NEC-AS HUIQB R1.0
 public static final String oid_pasoNeoIpe    = "1/3/1/1/4/";
 public static final String oid_pasoNeoIpe_new    = "1.3.6.1.4.1.119.2.3.69.501.2.3.3";
 public static final String  oid_pasoNeoIpe_old                  = "1.3.1.1.4.1.119.2.3.69.501.1.1.0.1";
 
 public static void testString(String oid){
  System.err.println(oid.substring(oid_pasoNeoIpe.length()));
 }
 
 //compare two String yes or no same
 public static boolean isThisCategory(String oid) {
  boolean result = false;
  if (oid.regionMatches(0, oid_pasoNeoIpe, 0, oid_pasoNeoIpe.length())) {
   result = true;
  }

  return result;
 }
 //string inversion to int type
 public static final int[] convertOToInts(String[] oid) {
  
  int[] oidints = null;
  if (0 < oid.length) {
   oidints = new int[oid.length];
   for (int i = 0; i < oid.length; i++) {
       int value = Integer.parseInt(oid[i]);
       oidints[i] = value;
   }
  }

  return oidints;
 }
 
 public static void main(String[] args) {
  //test split /
  String[] oidSplit = oid_pasoNeoIpe.split("/");
  int [] i = convertOToInts(oidSplit);
  if(0<i.length){
   for(int j = 0; j<i.length;j++){
    System.err.println("i=="+i[j]);
   }
  }
  //test split .
  String[] oidSplit1 = oid_pasoNeoIpe_new.split("\\.");
  int [] k = convertOToInts(oidSplit1);
  if(0<k.length){
   for(int j = 0; j<k.length;j++){
    System.err.println("k=="+k[j]);
   }
  }
  //test two string yes or no same
  System.out.println(isThisCategory(oid_pasoNeoIpe_old));
  
  //test subString method
  System.out.println(oid_pasoNeoIpe_old.substring(oid_pasoNeoIpe.length()));
  //System.err.println(isThisCategory(oid_pasoNeoIpe_new));
  
  //test length method
  System.err.println(oid_pasoNeoIpe.length());
  
   
 }
 public boolean test1(String s1,String s2){
  return s1.length() ==s2.length();
//  if(oid_pasoNeoIpe.length() ==oid_pasoNeoIpe_new.length()){
//   return true;
//   
//  }else {
//   return false;
//  }
 }
 //ADD_END-20101209 NEC-AS HUIQB R1.0
}

你可能感兴趣的:(J#)