hpstring.java
来自「一个简单的visio程序。」· Java 代码 · 共 2,075 行 · 第 1/5 页
JAVA
2,075 行
case Variant.V_INT:
case Variant.V_LONG:
str = varstr.strValue();
if( str==null )
throw new HpException(94,"Invalid use of null");
break;
case Variant.V_OBJ:
//Wrapper obj = varstr.getObject();
//if( obj==null )
// throw new HpException( 91, "Object variable or with block variable not set");
str = ((VObject)varstr).getDefaultProperty().strValue();
break;
case Variant.V_CURR:
case Variant.V_DBL:
case Variant.V_SINGLE:
str = Double.toString( varstr.dblValue() );
int len=str.length();
if( len>=3 && str.charAt(len-1)=='0' && str.charAt(len-2)=='.' )
str = str.substring(0,len-2);
break;
case Variant.V_DATE:
str = varstr.strValue();
break;
//case Variant.V_FORM:
// throw new HpException(450,"Wrong number of arguments or invalid property assignment");
default:
throw new HpException(13,"Type mismatch");
}
return new VString(str);
}
public static Variant LCASE(boolean bool_str) throws HpException
{
Boolean bol = new Boolean(bool_str);
return new VString( bol.toString().toLowerCase() );
}
public static Variant LCASE(HByte byt_str) throws HpException
{
return new VString( byt_str.strValue().toLowerCase());
}
public static Variant LCASE(short sh_str) throws HpException
{
return new VString(Short.toString(sh_str).toLowerCase());
}
public static Variant LCASE(int int_str) throws HpException
{
return new VString( Integer.toString(int_str).toLowerCase() );
}
public static Variant LCASE(float f_str) throws HpException
{
return new VString( Float.toString(f_str).toLowerCase() );
}
public static Variant LCASE(double d_str) throws HpException
{
return new VString( Double.toString(d_str).toLowerCase() );
}
public static Variant LCASE(HCurr vc_str) throws HpException
{
double d = vc_str.dblValue();
return new VString(Double.toString(d).toLowerCase());
}
public static Variant LCASE(HDate dt_str) throws HpException
{
return new VString(dt_str.strValue().toLowerCase() );
}
public static Variant LCASE(fixedString fixedstr) throws HpException
{
return new VString( fixedstr.strValue().toLowerCase() );
}
public static Variant LCASE(String str) throws HpException
{
return new VString( str.toLowerCase() );
}
/**
* UCase(string)
* Returns a string that has been converted to uppercase.
* The string argument is any valid string expression. If string contains Null,
Null is returned.
* Remarks
Only lowercase letters are converted to uppercase; all uppercase letters and nonletter characters remain unchanged.
*/
public static String UCASE$(Variant varstr) throws HpException
{
String str = get_str(varstr);
return str.toUpperCase();
}
public static String UCASE$(boolean bool_str) throws HpException
{
Boolean bool = new Boolean(bool_str);
return bool.toString().toUpperCase();
}
public static String UCASE$(HByte byt_str) throws HpException
{
return byt_str.strValue().toUpperCase();
}
public static String UCASE$(short sh_str) throws HpException
{
return Short.toString(sh_str).toUpperCase();
}
public static String UCASE$(int i_str) throws HpException
{
return Integer.toString(i_str).toUpperCase();
}
public static String UCASE$(float f_str) throws HpException
{
return Float.toString(f_str).toUpperCase();
}
public static String UCASE$(double d_str) throws HpException
{
return Double.toString(d_str).toUpperCase();
}
public static String UCASE$(HCurr vc_str) throws HpException
{
return vc_str.strValue().toUpperCase();
}
public static String UCASE$(HDate dt_str) throws HpException
{
return dt_str.strValue().toUpperCase();
}
public static String UCASE$(fixedString fixedstr) throws HpException
{
return (fixedstr.strValue() ).toUpperCase();
}
public static String UCASE$(String str) throws HpException
{
return str.toUpperCase();
}
/*--- FUNCTION: UCase(string) ---*/
public static Variant UCASE(Variant varstr) throws HpException
{
String str="";
switch (varstr.getType())
{
case Variant.V_NULL:
return new VNull();
case Variant.V_FIX_STR:
fixedString fix_str = ((VString)varstr).getfixedLenStrValue();
str = fix_str.strValue();
break;
case Variant.V_STR:
case Variant.V_EMPTY:
case Variant.V_BOL:
case Variant.V_BYTE:
case Variant.V_INT:
case Variant.V_LONG:
str = varstr.strValue();
if( str==null )
throw new HpException(94,"Invalid use of null");
break;
case Variant.V_OBJ:
//Wrapper obj = varstr.getObject();
//if( obj==null )
//throw new HpException( 91, "Object variable or with block variable not set");
str = ((VObject)varstr).getDefaultProperty().strValue();
break;
case Variant.V_CURR:
case Variant.V_DBL:
case Variant.V_SINGLE:
str = Double.toString( varstr.dblValue() );
int len=str.length();
if( len>=3 && str.charAt(len-1)=='0' && str.charAt(len-2)=='.' )
str = str.substring(0,len-2);
int ePos = str.indexOf('E');
if( ePos!=-1 )
{
char chr = str.charAt(ePos+1 );
if( chr != '-' )
str = str.substring(0,ePos+1) + "+" + str.substring(ePos+1 );
}
break;
case Variant.V_DATE:
str = varstr.strValue();
break;
//case Variant.V_FORM:
// throw new HpException(450,"Wrong number of arguments or invalid property assignment");
default:
throw new HpException(13,"Type mismatch");
}
return new VString(str);
}
public static Variant UCASE(boolean bool_str) throws HpException
{
Boolean bool = new Boolean(bool_str);
return new VString(bool.toString().toUpperCase());
}
public static Variant UCASE(HByte byt_str) throws HpException
{
return new VString(byt_str.strValue().toUpperCase());
}
public static Variant UCASE(short sh_str) throws HpException
{
return new VString( Short.toString(sh_str).toUpperCase() );
}
public static Variant UCASE(int i_str) throws HpException
{
return new VString( Integer.toString(i_str).toUpperCase() );
}
public static Variant UCASE(float f_str) throws HpException
{
return new VString( Float.toString(f_str).toUpperCase() );
}
public static Variant UCASE(double d_str) throws HpException
{
return new VString(Double.toString(d_str).toUpperCase());
}
public static Variant UCASE(HCurr vc_str) throws HpException
{
return new VString(vc_str.strValue().toUpperCase());
}
public static Variant UCASE(HDate dt_str) throws HpException
{
return new VString(dt_str.strValue().toUpperCase());
}
public static Variant UCASE(fixedString fixedstr) throws HpException
{
return new VString( fixedstr.strValue().toUpperCase() );
}
public static Variant UCASE(String str) throws HpException
{
return new VString(str.toUpperCase());
}
/**
* Left[$](string, length)
* string String expression from which the leftmost characters are returned.
If string contains Null, Null is returned.
* length Numeric expression indicating how many characters to return. If 0,
a zero-length string is returned,If greater than or equal to the
number of characters in string, the entire string is returned.
* Returns a specified number of characters from the right side of a string.
left$() return a string, left() return a variant string.
* Remarks
To determine the number of characters in string, use the Len function.
* Note
LeftB(String, length) is provided for use with byte data contained in a string.
Instead of specifying the number of characters to return, length specifies the
number of bytes.
*/
public static String LEFT$(Variant varstr, Variant varlen) throws HpException
{
int len=0;
String str = get_str( varstr);
len = (int)Math.round( varlen.dblValue() );
if( len<0 || len>65535)
throw new HpException(95, "Invalid procedure call");
if( len==0 )
return "";
else if( len >= str.length() )
return str;
else
return str.substring(0,len);
}
/*--- FUNCTION: Left(string,int) ---*/
public static String LEFTB$(Variant varstr, Variant varlen) throws HpException
{
int len=0;
String str = get_str( varstr);
len = (int)Math.round( varlen.dblValue() );
if( len<0 || len>65535)
throw new HpException(95, "Invalid procedure call");
if( len==0 )
return "";
else if( len >= str.length() )
return str;
else
return str.substring(0,(int)(len/2));
}
/*--- FUNCTION: Left(string,int) ---*/
public static Variant LEFTB(Variant varstr, Variant varlen) throws HpException
{
String s=null;
int type = varstr.getType();
if( type==Variant.V_NULL)
return new VNull();
else
{
s = LEFTB$(varstr,varlen);
return new VString(s);
}
}
/*--- FUNCTION: Left(string,int) ---*/
public static Variant LEFT(Variant varstr, Variant varlen) throws HpException
{
int type = varstr.getType();
if( type==Variant.V_NULL)
return new VNull();
else
{
String s = LEFT$(varstr,varlen);
return new VString(s);
}
}
/**
* Right[$](string, length)
* Right$() return a string,Right() return a variant string.
* string String expression from which the rightmost characters are returned.
If string contains Null, Null is returned.
* length Numeric expression indicating how many characters to return. If 0,
a zero-length string is returned. If greater than or equal to the
number of characters in string, the entire string is returned.
* Note
RightB(string,length) is provided for use with byte data contained within
a string. Instead of specifying the number of characters to return, length
specifies the number of bytes.
*/
public static String RIGHTB$(Variant varstr, Variant varlen) throws HpException
{
String str;
int len=0;
str = get_str( varstr);
len = (int)Math.round( varlen.dblValue() );
if( len < 0 || len > 65535 )
throw new HpException(95,"Invalid procedure call");
if( len==0 )
return "";
else if( len>=str.length() )
return str ;
else
return str.substring(str.length()-(int)(len/2) ) ;
}
/*--- FUNCTION: RightB(string,int) ---*/
public static Variant RIGHTB(Variant varstr, Variant varlen ) throws HpException
{
if( varstr.getType() == Variant.V_NULL)
return new VNull();
else
{
String s = RIGHTB$(varstr, varlen);
return new VString(s);
}
}
/*--- FUNCTION: Right$(string,int) ---*/
public static String RIGHT$(Variant varstr, Variant varlen) throws HpException
{
String str;
int len=0;
str = get_str( varstr);
len = (int)Math.round( varlen.dblValue() );
if( len < 0 || len > 65535 )
throw new HpException(95,"Invalid procedure call");
if( len==0 )
return "";
else if( len>=str.length() )
return str;
else
return str.substring(str.length()-len) ;
}
/*--- FUNCTION: Right(string,int) ---*/
public static Variant RIGHT(Variant varstr, Variant varlen ) throws HpException
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?