本文整理汇总了Java中java.lang.String.length方法的典型用法代码示例。如果您正苦于以下问题:Java String.length方法的具体用法?Java String.length怎么用?Java String.length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.String
的用法示例。
在下文中一共展示了String.length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: msg
import java.lang.String; //导入方法依赖的package包/类
/**
* Returns the message text corresponding to the passed msgkey
* string. The message text is assumed to require the insertion
* of a single argument, supplied by the "parm" parameter.
* If the message text does not contain the meta characters "%1"
* that indicate where to place the argument, the passed argument
* is appended at the end of the message text.
* <p>
* If the msgkey cannot be found, its value is used as the
* message text.
*/
public static final String msg (String msgkey, String parm) {
if (loadNeeded)
loadDefaultProperties ();
String msgtext = m.getProperty (msgkey, msgkey);
int i = msgtext.indexOf ("%1");
if (i >= 0) {
String ending = "";
if ((i+2) < msgtext.length ())
ending = msgtext.substring (i+2);
return msgtext.substring (0, i) + parm + ending;
} else
msgtext += " " + parm;
return msgtext;
}
示例2: normalizeSpace
import java.lang.String; //导入方法依赖的package包/类
public static String normalizeSpace(String a) {
StringBuffer result = new StringBuffer();
boolean needSpace = false;
for (int i = 0; i < a.length(); i++) {
char c = a.charAt(i);
if (c == ' ' || c == '\t' || c == '\n' || c == '\r')
needSpace = true;
else
{
if (needSpace && result.length() != 0)
result.append(' ');
result.append(c);
needSpace = false;
}
}
return result.toString();
}
示例3: tokenize
import java.lang.String; //导入方法依赖的package包/类
public static IEnumerable tokenize(String input, String delimiter)
{
ArrayList<String> tokens = new ArrayList<String>();
int i=0;
int j=0;
int dl = delimiter.length();
//int il = input.length();
while(true)
{
i = input.indexOf(delimiter, j);
if (i == -1)
{
tokens.add(input.substring(j));
break;
}
tokens.add(input.substring(j, i));
j = i + dl;
}
return new com.altova.mapforce.MFElement.ArrayListAsEnumerable(tokens);
}
示例4: substituteString
import java.lang.String; //导入方法依赖的package包/类
private static String substituteString(String orig, int paramNum,
String subst){
String result = orig;
String paramSubst = "%"+ paramNum;
int len = paramSubst.length();
int index = result.indexOf (paramSubst);
String ending = "";
if (index >= 0) {
if ((index+len) < result.length ())
ending = result.substring (index+len);
result = result.substring (0, index) + subst + ending;
}
else result += " " + subst;
return result;
}
示例5: lexSqlScript
import java.lang.String; //导入方法依赖的package包/类
public static List<String> lexSqlScript(String sqlScript) {
ArrayList<String> sl = new ArrayList<String>();
boolean inString = false, quoteNext = false;
StringBuilder b = new StringBuilder(100);
for (int i = 0; i < sqlScript.length(); i++) {
char c = sqlScript.charAt(i);
if (c == ';' && !inString && !quoteNext) {
sl.add(b.toString());
b = new StringBuilder(100);
inString = false;
quoteNext = false;
continue;
}
if (c == '\'' && !quoteNext) {
inString = !inString;
}
quoteNext = c == '\\' && !quoteNext;
b.append(c);
}
if (b.length() > 0) {
sl.add(b.toString());
}
return sl;
}
示例6: castToString
import java.lang.String; //导入方法依赖的package包/类
public static String castToString(BigDecimal val)
{
int sign = val.signum();
val = val.abs();
String s = val.unscaledValue().toString();
while (s.length() <= val.scale()) s = "0" + s;
while (s.length() < -val.scale()) s = s + "0";
if (val.scale() > 0) {
s = s.substring(0, s.length() - val.scale()) + "." + s.substring(s.length() - val.scale(), s.length());
while (s.endsWith("0")) s = s.substring(0, s.length() - 1);
if (s.endsWith(".")) s = s.substring(0, s.length() - 1);
}
if (sign < 0) s = "-" + s;
return s;
}
示例7: castToDateTime
import java.lang.String; //导入方法依赖的package包/类
public static DateTime castToDateTime(String s)
{
if (s == null)
throw new java.lang.NullPointerException();
if (s.length() == 0)
throw new IllegalArgumentException("Cast to DateTime failed.");
return DateTime.parse( s );
}
示例8: castToDuration
import java.lang.String; //导入方法依赖的package包/类
public static Duration castToDuration(String s, Duration.ParseType pt)
{
if (s == null)
throw new java.lang.NullPointerException();
if (s.length() == 0)
throw new IllegalArgumentException("Cast to Duration failed.");
return Duration.parse( s, pt );
}
示例9: substring
import java.lang.String; //导入方法依赖的package包/类
public static String substring(String str, int start, int length) {
int from = start;
int to = start + length;
if (from < 1) from = 1;
if (to > str.length() + 1) to = str.length() + 1;
if (to <= from) return "";
int rfrom = from - 1;
int rto = to - 1;
return str.substring(rfrom, rto);
}
示例10: translate
import java.lang.String; //导入方法依赖的package包/类
public static String translate(String a, String b, String c) {
String result = "";
for (int i = 0 ; i < a.length(); i++) {
char ai = a.charAt(i);
int off = b.indexOf(ai);
if (off != -1 && off < c.length())
result += c.charAt(off);
else if (off == -1)
result += ai;
}
return result;
}
示例11: appendPath
import java.lang.String; //导入方法依赖的package包/类
/**
* Utility method for appending path from pathFrom to pathTo.
*
* @param pathTo the target path
* @param pathFrom the path to be appended to pathTo
* @return the resulting path
*/
public static String appendPath(String pathTo, String pathFrom) {
if (pathTo == null || pathTo.length() == 0) {
return pathFrom;
} else if (pathFrom == null || pathFrom.length() == 0) {
return pathTo;
} else {
return pathTo + File.pathSeparator + pathFrom;
}
}
示例12: appendPath
import java.lang.String; //导入方法依赖的package包/类
/**
* Utility method for appending path from pathFrom to pathTo.
*
* @param pathTo the target path
* @param pathSource the path to be appended to pathTo
* @return the resulting path
*/
public static String appendPath(String pathTo, String pathFrom) {
if (pathTo == null || pathTo.length() == 0) {
return pathFrom;
} else if (pathFrom == null || pathFrom.length() == 0) {
return pathTo;
} else {
return pathTo + File.pathSeparator + pathFrom;
}
}
示例13: ParseDateTime
import java.lang.String; //导入方法依赖的package包/类
public static DateTime ParseDateTime(String sInput, String sPattern)
{
if( sPattern.length() == 0 )
throw new IllegalArgumentException( "Empty pattern.");
DateTimeFormatParser dtfp = new DateTimeFormatParser( sPattern);
return dtfp.parseDateTime( sInput);
}
示例14: createNamespace
import java.lang.String; //导入方法依赖的package包/类
public static com.altova.mapforce.IMFNode createNamespace(String prefix, String content)
{
if (prefix.length() == 0)
return new com.altova.mapforce.MFAttribute("xmlns", "http://www.w3.org/2000/xmlns/", "", box(content));
else
return new com.altova.mapforce.MFAttribute(prefix, "http://www.w3.org/2000/xmlns/", "xmlns", box(content));
}
示例15: fixMessages
import java.lang.String; //导入方法依赖的package包/类
/**
* This method was introduced to fix defect #26964. For Java 1.0.2
* on Win NT, the escape sequence \u0020 was not being handled
* correctly by the Java Properties class when it was the final
* character of a line. Instead the trailing blank was dropped
* and the next line was swallowed as a continuation. To work
* around the problem, we introduced our own metasymbol to represent
* a trailing blank. Hence:
*
* Performs substitution for any metasymbols in the message
* templates. So far only %B is needed. This was introduced
* to make it more convenient for .properties files to
* contain message templates with leading or trailing blanks
* (although %B may actually occur anywhere in a template).
* Subsequently, checking for '\n' has also been added. Now,
* wherever '\n' occurs in a message template, it is replaced
* with the value of System.getProperty ("line.separator").
*/
private static final void fixMessages (Properties p) {
Enumeration keys = p.keys ();
Enumeration elems = p.elements ();
while (keys.hasMoreElements ()) {
String key = (String) keys.nextElement ();
String elem = (String) elems.nextElement ();
int i = elem.indexOf (LTB);
boolean changed = false;
while (i != -1) {
if (i == 0)
elem = " " + elem.substring (2);
else
elem = elem.substring (0, i) + " " + elem.substring (i+2);
changed = true;
i = elem.indexOf (LTB);
}
int lsIncr = lineSeparator.length () - 1;
for (i=0; i<elem.length (); i++) {
if (elem.charAt (i) == NL) {
elem = elem.substring (0, i) +
lineSeparator + elem.substring (i+1);
i += lsIncr;
changed = true;
}
}
if (changed)
p.put (key, elem);
}
}