本文整理汇总了C#中String.length方法的典型用法代码示例。如果您正苦于以下问题:C# String.length方法的具体用法?C# String.length怎么用?C# String.length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类String
的用法示例。
在下文中一共展示了String.length方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: reverseWords
// A2: reverse the whole string, detect each word and reverse the word
// Pitfall: need extra work to remove continuous space
public String reverseWords(String input)
{
if (input==null || input.length() == 0) return input;
StringBuilder a = new StringBuilder(input);
int start = -1;
int end = -1;
reverse(a, 0, a.length()-1);
for (int i=0; i<=a.length(); i++)
{
if (i == a.length() || a.charAt(i) == ' ')
{
if (start < end) reverse(a, start+1, end);
start = i;
}
else
{
end = i;
}
}
return a.toString();
}
示例2: replace
public virtual AbstractStringBuilder replace(int start, int end, String str)
{
if (start < 0)
throw new IndexOutOfRangeException();
if (start > count)
throw new IndexOutOfRangeException("start > length()");
if (start > end)
throw new IndexOutOfRangeException("start > end");
if (end > count)
end = count;
int len = str.length();
int newCount = count + len - (end - start);
ensureCapacityInternal(newCount);
Array.Copy(value, end, value, start + len, count - end);
str.getChars(value, start);
count = newCount;
return this;
}
示例3: lastIndexOf
public virtual int lastIndexOf(String str, int fromIndex)
{
return String.lastIndexOf(value, 0, count,
str.toCharArray(), 0, str.length(), fromIndex);
}
示例4: indexOf
public new int indexOf(String str, int fromIndex)
{
return String.indexOf(value, 0, count,
str.toCharArray(), 0, str.length(), fromIndex);
}
示例5: StringBuilder
public StringBuilder(String str)
: base(str.length() + 16)
{
append(str);
}
示例6: pushResolved
/**
*
* @param qxri QXRI that was resolved
* @param xrds XRDS document received
* @param uri URI queried to resolve the QXRI
*/
public void pushResolved(String qxri, String trustType, String xrds, URI uri)
{
ResolverStep step = new ResolverStep(qxri, trustType, xrds, null, uri);
steps.add(step);
numRequests++;
numBytesReceived += xrds.length();
}
示例7: decode
public static Long decode(String nm)
{
int radix = 10;
int index = 0;
boolean negative = false;
Long result;
if (nm.length() == 0)
throw new NumberFormatException("Zero length string");
char firstChar = nm.charAt(0);
// Handle sign, if present
if (firstChar == '-') {
negative = true;
index++;
} else if (firstChar == '+')
index++;
// Handle radix specifier, if present
if (nm.startsWith(new String("0x"), index) || nm.startsWith(new String("0X"), index)) {
index += 2;
radix = 16;
}
else if (nm.startsWith(new String("#"), index)) {
index ++;
radix = 16;
}
else if (nm.startsWith(new String("0"), index) && nm.length() > 1 + index) {
index ++;
radix = 8;
}
if (nm.startsWith(new String("-"), index) || nm.startsWith(new String("+"), index))
throw new NumberFormatException("Sign character in wrong position");
try {
result = Long.valueOf(nm.substring(index), radix);
result = negative ? Long.valueOf(-result.longValue()) : result;
} catch (NumberFormatException) {
// If number is Long.MIN_VALUE, we'll end up here. The next line
// handles this case, and causes any genuine format error to be
// rethrown.
String constant = negative ? new String("-" + nm.substring(index))
: nm.substring(index);
result = Long.valueOf(constant, radix);
}
return result;
}
示例8: reverseWords
public String reverseWords(String s)
{
if (s == null)
{
return s;
}
int begin = 0;
int end = 0;
while (begin < s.length() && s.charAt(begin) == ' ')
{
begin++;
}
if (begin == s.length())
{
return "";
}
if (s.length() <= 1)
{
return s;
}
StringBuilder result = new StringBuilder("");
while (begin < s.length() && end < s.length())
{
while (begin < s.length() && s.charAt(begin) == ' ')
{
begin++;
}
if (begin == s.length())
{
break;
}
end = begin + 1;
while (end < s.length() && s.charAt(end) != ' ')
{
end++;
}
if (result.length() != 0)
{
result.insert(0, " ");
}
if (end < s.length())
{
result.insert(0, s.substring(begin, end));
}
else
{
result.insert(0, s.substring(begin, s.length()));
break;
}
begin = end + 1;
}
return result.toString();
}
示例9: parseLong
public static long parseLong(String s, int radix)
{
if (s == null) {
throw new NumberFormatException("null");
}
if (radix < Character.MIN_RADIX) {
throw new NumberFormatException("radix " + radix +
" less than Character.MIN_RADIX");
}
if (radix > Character.MAX_RADIX) {
throw new NumberFormatException("radix " + radix +
" greater than Character.MAX_RADIX");
}
long result = 0;
boolean negative = false;
int i = 0, len = s.length();
long limit = -Long.MAX_VALUE;
long multmin;
int digit;
if (len > 0) {
char firstChar = s.charAt(0);
if (firstChar < '0') { // Possible leading "+" or "-"
if (firstChar == '-') {
negative = true;
limit = Long.MIN_VALUE;
} else if (firstChar != '+')
throw NumberFormatException.forInputString(s);
if (len == 1) // Cannot have lone "+" or "-"
throw NumberFormatException.forInputString(s);
i++;
}
multmin = limit / radix;
while (i < len) {
// Accumulating negatively avoids surprises near MAX_VALUE
digit = Character.digit(s.charAt(i++),radix);
if (digit < 0) {
throw NumberFormatException.forInputString(s);
}
if (result < multmin) {
throw NumberFormatException.forInputString(s);
}
result *= radix;
if (result < limit + digit) {
throw NumberFormatException.forInputString(s);
}
result -= digit;
}
} else {
throw NumberFormatException.forInputString(s);
}
return negative ? result : -result;
}