| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- package UIB.UIB03.ZBS;
- /**
- *
- * @desc String类型的数字或者字母转换为质保书所对应的行或列
- * @author meiguiping
- * @date 2010 11:35:45 AM
- */
- public class StringFormat
- {
- public static int getNumber(String str) throws Exception
- {
- int r = 0;
- str = str.toUpperCase();
-
- //string类型是否满足要求
- if(!str.matches("[A-Z]+") && !str.matches("[0-9]+") )
- {
- throw new Exception("数据类型错误,请检查!");
- }
-
- if(str.matches("[0-9]+"))
- {
- r = Integer.parseInt(str)-1;
- return r;
- }
-
-
- int len = str.length();
- switch(len)
- {
-
- case 0:
- r = 0;
- break;
- case 1:
- r = (int)str.charAt(0)-65;//A的ASCII码值为65
- break;
- case 2:
- r = (int)str.charAt(1)-64+((int)str.charAt(0)-65+25);//长度为2时
- // default:
- // r = 111;
- // break;
- }
- return r;
- }
- }
|