df51266c74b71da4c78ac9564b44bbcebc1abc0d.svn-base 809 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package UIB.UIB03.ZBS;
  2. /**
  3. *
  4. * @desc String类型的数字或者字母转换为质保书所对应的行或列
  5. * @author meiguiping
  6. * @date 2010 11:35:45 AM
  7. */
  8. public class StringFormat
  9. {
  10. public static int getNumber(String str) throws Exception
  11. {
  12. int r = 0;
  13. str = str.toUpperCase();
  14. //string类型是否满足要求
  15. if(!str.matches("[A-Z]+") && !str.matches("[0-9]+") )
  16. {
  17. throw new Exception("数据类型错误,请检查!");
  18. }
  19. if(str.matches("[0-9]+"))
  20. {
  21. r = Integer.parseInt(str)-1;
  22. return r;
  23. }
  24. int len = str.length();
  25. switch(len)
  26. {
  27. case 0:
  28. r = 0;
  29. break;
  30. case 1:
  31. r = (int)str.charAt(0)-65;//A的ASCII码值为65
  32. break;
  33. case 2:
  34. r = (int)str.charAt(1)-64+((int)str.charAt(0)-65+25);//长度为2时
  35. // default:
  36. // r = 111;
  37. // break;
  38. }
  39. return r;
  40. }
  41. }