本文整理汇总了Java中java.lang.String.indexOf方法的典型用法代码示例。如果您正苦于以下问题:Java String.indexOf方法的具体用法?Java String.indexOf怎么用?Java String.indexOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.String
的用法示例。
在下文中一共展示了String.indexOf方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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;
}
示例3: 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;
}
示例4: 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";
}
示例5: castToString
import java.lang.String; //导入方法依赖的package包/类
public static String castToString(double d)
{
double dAbs = Math.abs(d);
DecimalFormatSymbols decfmtsymb = new DecimalFormatSymbols(java.util.Locale.US); // US locale represents numbers with a . as comma and without any (ten)thousend separators.
decfmtsymb.setInfinity("INF");
decfmtsymb.setNaN("NaN");
DecimalFormat decfmt = new DecimalFormat((dAbs > 1E7 || dAbs < 1E-3) && dAbs > 0.0 ?
"0.##############E000" : "0.#############", decfmtsymb);
String s = decfmt.format(d);
// 1.234E567 => 1.234E+567
int e = s.indexOf("E");
if (e > 0 && s.charAt(e+1) != '-' )
s = s.substring(0, e) + "E+" + s.substring(e+1);
return s;
}
示例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);
}
示例7: 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 "";
}
示例8: 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 "";
}
示例9: 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;
}
示例10: 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, "");
}
示例11: 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);
}
}
示例12: contains
import java.lang.String; //导入方法依赖的package包/类
public static boolean contains(String str, String substr) {
return str.indexOf(substr) >= 0;
}
示例13: readBoard
import java.lang.String; //导入方法依赖的package包/类
public void readBoard(String in,boolean update){
moveSequence = "";
redTurn = true;
blueTurn = false;
try{
String[] parts;
boolean newMode = false;
char[] id = in.toCharArray();
if(id[0]=='B'){
int indexOfFirstComma = in.indexOf(",");
int indexOfFirstSlash = in.indexOf("/");
birth.clear();
survive.clear();
for(int i=1;i<indexOfFirstSlash;i++){
birth.add(Character.getNumericValue(id[i]));
}
for(int i=indexOfFirstSlash+2;i<indexOfFirstComma;i++){
survive.add(Character.getNumericValue(id[i]));
}
parts = in.substring(indexOfFirstComma+1).split(",");
}else{
parts = in.split(",");
}
if (parts.length < 5) {
throw new IOException();
}
WIDTH = HEIGHT = Math.min(Math.max(Integer.parseInt(parts[0]),3),20);
timeLimit[0]=0;
timeLimit[1] = Integer.parseInt(parts[1]);
timeLimit[2]=0;
timeLimit[3]=0;
timeBonus = Integer.parseInt(parts[2]);
int humanNum = Integer.parseInt(parts[3]);
stringToBoard(parts[4],update);
/*redDepth = (int)(((humanNum/4)-1)*2);
blueDepth = (((humanNum%4)-1)*2);
if(redDepth<0){
redBot = false;
}else{
redBot = true;
}
if(blueDepth<0){
blueBot = false;
}else{
redBot = true;
}*/
int noSwapsUntil = -1;
String[] moves = new String[parts.length-5];
for(int i = 0; i<moves.length; i++){
moves[i]=parts[i+5];
}
int moveLimit = Integer.MAX_VALUE;
if(screen==4){
moveArray = moves;
totalMoves = moveArray.length;
moveNumber = 0;
saveTiles();
}else{
saveTiles();
for (int t = 0; t < moves.length; t++) { // Go through all the moves.
makeMove(moves[t]);
}
}
updateNumbers();
updateLists();
boardStart = getBoard();
}catch (Exception e) {
JFrame frame = new JFrame("Error");
JOptionPane.showMessageDialog(frame, "Illegal game string", "Error", 0);
}
}