当前位置: 技术问答>java相关
java填充相同字符的方法?
来源: 互联网 发布时间:2015-08-22
本文导语: java里有没有填充一串相同字符(比如空格,0,或空值)的方法? | public static String PadTrailing(String rString, int rLength, String rPad) { String lTmpPad = ""; String lT...
java里有没有填充一串相同字符(比如空格,0,或空值)的方法?
|
public static String PadTrailing(String rString, int rLength, String rPad) {
String lTmpPad = "";
String lTmpStr = StrChkNull(rString);
if (lTmpStr.length() >= rLength)
return lTmpStr.substring(0,lTmpStr.length());
else {
for(gCnt = 1; gCnt = rLength)
return lTmpStr.substring(0,lTmpStr.length());
else {
for(gCnt = 1; gCnt stringLength)
{
int max = 0;
String S4 = "";
for(int i = 0; i sourceString.length()? sourceString.length():i + stringLength;
String S3 = sourceString.substring(i, max);
if(!S3.equals(toReplaceString))
{
S4 += S3.substring(0,1);
}
else
{
S4 += replaceString;
i += stringLength -1 ;
}
}
returnString = S4;
}
return returnString;
}
String lTmpPad = "";
String lTmpStr = StrChkNull(rString);
if (lTmpStr.length() >= rLength)
return lTmpStr.substring(0,lTmpStr.length());
else {
for(gCnt = 1; gCnt = rLength)
return lTmpStr.substring(0,lTmpStr.length());
else {
for(gCnt = 1; gCnt stringLength)
{
int max = 0;
String S4 = "";
for(int i = 0; i sourceString.length()? sourceString.length():i + stringLength;
String S3 = sourceString.substring(i, max);
if(!S3.equals(toReplaceString))
{
S4 += S3.substring(0,1);
}
else
{
S4 += replaceString;
i += stringLength -1 ;
}
}
returnString = S4;
}
return returnString;
}