本文整理匯總了Java中java.lang.String.charAt方法的典型用法代碼示例。如果您正苦於以下問題:Java String.charAt方法的具體用法?Java String.charAt怎麽用?Java String.charAt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.lang.String
的用法示例。
在下文中一共展示了String.charAt方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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();
}
示例2: 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;
}
示例3: 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;
}
示例4: 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;
}
示例5: 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;
}
示例6: 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);
}
}