当前位置: 首页>>代码示例>>Java>>正文


Java String.length方法代码示例

本文整理汇总了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;

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:Messages.java

示例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();
}
 
开发者ID:CenPC434,项目名称:java-tools,代码行数:18,代码来源:Core.java

示例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);
}
 
开发者ID:CenPC434,项目名称:java-tools,代码行数:22,代码来源:Core.java

示例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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:17,代码来源:Messages.java

示例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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:32,代码来源:SQLiteUtils.java

示例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;
}
 
开发者ID:CenPC434,项目名称:java-tools,代码行数:16,代码来源:CoreTypes.java

示例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 );
}
 
开发者ID:CenPC434,项目名称:java-tools,代码行数:9,代码来源:CoreTypes.java

示例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 );
}
 
开发者ID:CenPC434,项目名称:java-tools,代码行数:9,代码来源:CoreTypes.java

示例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);
}
 
开发者ID:CenPC434,项目名称:java-tools,代码行数:11,代码来源:Core.java

示例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;
}
 
开发者ID:CenPC434,项目名称:java-tools,代码行数:13,代码来源:Core.java

示例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;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:PathList.java

示例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;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:17,代码来源:PathList.java

示例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);
}
 
开发者ID:CenPC434,项目名称:java-tools,代码行数:10,代码来源:Core.java

示例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));
}
 
开发者ID:CenPC434,项目名称:java-tools,代码行数:8,代码来源:Core.java

示例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);
    }

}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:50,代码来源:Messages.java


注:本文中的java.lang.String.length方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。