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


Java String.substring方法代码示例

本文整理汇总了Java中java.lang.String.substring方法的典型用法代码示例。如果您正苦于以下问题:Java String.substring方法的具体用法?Java String.substring怎么用?Java String.substring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.String的用法示例。


在下文中一共展示了String.substring方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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:SunburstApps,项目名称:OpenJSharp,代码行数:28,代码来源:Messages.java

示例2: 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

示例3: NumberParts

import java.lang.String; //导入方法依赖的package包/类
public NumberParts(String input)
{
	input = input.trim();
	if (input.startsWith("-"))
	{
		sign = "-";
		input = input.substring(1);
	}
	else if (input.startsWith("+"))
	{
		sign = "";
		input = input.substring(1);
	}
	else
		sign = "";
	int indexOfE = input.indexOf('e');
	if (indexOfE < 0)
		indexOfE = input.indexOf('E');
	if (indexOfE < 0)
	{
		mantissa = input;
		exponent = "";
	}
	else
	{
		mantissa = input.substring(0, indexOfE);
		exponent = input.substring(indexOfE + 1);
	}

	if (mantissa.startsWith("."))
		mantissa = "0" + mantissa;
	if (mantissa.endsWith("."))
		mantissa = mantissa + "0";
	if (mantissa.length() == 0)
		mantissa = "0";
	if (exponent.endsWith("+") || exponent.endsWith("-"))
		exponent = exponent + "0";
}
 
开发者ID:CenPC434,项目名称:java-tools,代码行数:39,代码来源:CoreTypes.java

示例4: locateLocaleSpecificFileInClassPath

import java.lang.String; //导入方法依赖的package包/类
/**
 * locateLocaleSpecificFileInClassPath returns a DataInputStream that
 * can be used to read the requested file, but the name of the file is
 * determined using information from the current locale and the supplied
 * file name (which is treated as a "base" name, and is supplemented with
 * country and language related suffixes, obtained from the current
 * locale).  The CLASSPATH is used to locate the file.
 *
 * @param fileName The name of the file to locate.  The file name
 * may be qualified with a partial path name, using '/' as the separator
 * character or using separator characters appropriate for the host file
 * system, in which case each directory or zip file in the CLASSPATH will
 * be used as a base for finding the fully-qualified file.
 * Here is an example of how the supplied fileName is used as a base
 * for locating a locale-specific file:
 *
 * <pre>
 *     Supplied fileName: a/b/c/x.y,  current locale: US English
 *
 *                     Look first for: a/b/c/x_en_US.y
 *     (if that fails) Look next for:  a/b/c/x_en.y
 *     (if that fails) Look last for:  a/b/c/x.y
 *
 *     All elements of the class path are searched for each name,
 *     before the next possible name is tried.
 * </pre>
 *
 * @exception java.io.FileNotFoundException The requested class file
 * could not be found.
 * @exception java.io.IOException The requested class file
 * could not be opened.
 */
public static DataInputStream locateLocaleSpecificFileInClassPath (
    String fileName) throws FileNotFoundException, IOException {

    String localeSuffix = "_" + Locale.getDefault ().toString ();
    int lastSlash = fileName.lastIndexOf ('/');
    int lastDot   = fileName.lastIndexOf ('.');
    String fnFront, fnEnd;
    DataInputStream result = null;
    boolean lastAttempt = false;

    if ((lastDot > 0) && (lastDot > lastSlash)) {
        fnFront = fileName.substring (0, lastDot);
        fnEnd   = fileName.substring (lastDot);
    } else {
        fnFront = fileName;
        fnEnd   = "";
    }

    while (true) {
        if (lastAttempt)
            result = locateFileInClassPath (fileName);
        else try {
            result = locateFileInClassPath (fnFront + localeSuffix + fnEnd);
        } catch (Exception e) { /* ignore */ }
        if ((result != null) || lastAttempt)
            break;
        int lastUnderbar = localeSuffix.lastIndexOf ('_');
        if (lastUnderbar > 0)
            localeSuffix = localeSuffix.substring (0, lastUnderbar);
        else
            lastAttempt = true;
    }
    return result;

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

示例5: 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

示例6: castToQName

import java.lang.String; //导入方法依赖的package包/类
public static javax.xml.namespace.QName castToQName(String s)
{
	int i = s.indexOf('{');
	int j = s.indexOf('}');
	if (i==0 && j>i)
		return new javax.xml.namespace.QName(s.substring(1, j), s.substring(j+1));
	
	return new javax.xml.namespace.QName(s);
}
 
开发者ID:CenPC434,项目名称:java-tools,代码行数:10,代码来源:CoreTypes.java

示例7: formatFraction

import java.lang.String; //导入方法依赖的package包/类
public static String formatFraction(long value, long precision)
{
	String result = "";
	if (value != 0)
	{
		result += '.';
		result += formatNumber(value, precision);
		int i = result.length();
		while (result.charAt(i - 1) == '0')
			i -= 1;
		result = result.substring( 0, i );
	}
	return result;
}
 
开发者ID:CenPC434,项目名称:java-tools,代码行数:15,代码来源:CoreTypes.java

示例8: 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

示例9: substringAfter

import java.lang.String; //导入方法依赖的package包/类
public static String substringAfter(String str, String substr) {
	int position = str.indexOf(substr);
	if (position >= 0)
		return (str.substring(position + substr.length()));
	else
		return "";
}
 
开发者ID:CenPC434,项目名称:java-tools,代码行数:8,代码来源:Core.java

示例10: substringBefore

import java.lang.String; //导入方法依赖的package包/类
public static String substringBefore(String str, String substr) {
	int position = str.indexOf(substr);
	if (position >= 0)
		return str.substring(0, position);
	else
		return "";
}
 
开发者ID:CenPC434,项目名称:java-tools,代码行数:8,代码来源:Core.java

示例11: createQName

import java.lang.String; //导入方法依赖的package包/类
public static javax.xml.namespace.QName createQName(String localname, String uri)
{
	int sep = localname.indexOf(':');
	if (sep >= 0)
		return new javax.xml.namespace.QName(uri, localname.substring(sep + 1), localname.substring(0, sep));
	else
		return new javax.xml.namespace.QName(uri, localname, "");
}
 
开发者ID:CenPC434,项目名称:java-tools,代码行数:9,代码来源:Core.java

示例12: 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

示例13: convertFilenameToTitle

import java.lang.String; //导入方法依赖的package包/类
private static String convertFilenameToTitle(String filename){
    String title = filename.substring(0, filename.lastIndexOf("."));
    title = title.replace("Cant", "Can't");
    return title;
}
 
开发者ID:Captwalloper,项目名称:NUI_Project,代码行数:6,代码来源:PrototypeSongsLocalDataSource.java


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