测试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
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值