public static int CompareOrdinal(java.lang.String strA, int indexA, java.lang.String strB, int indexB, int length) { if (object.ReferenceEquals(strA, strB)) { return(0); } if (strA == null) { return(-1); } if (strB == null) { return(1); } int endIndexA, endIndexB; if (indexA < 0 || (endIndexA = indexA + length) > strA.length() || indexB < 0 || (endIndexB = indexB + length) > strB.length()) { throw new System.ArgumentOutOfRangeException(); } return(((java.lang.String)(object) strA.substring(indexA, endIndexA)) .compareTo((java.lang.String)(object) strB.substring(indexB, endIndexB))); }
public static string Replace(java.lang.String str, string oldStr, string newStr) { ThrowHelper.ThrowIfNull(oldStr); int lenOld = ((java.lang.String)(object) oldStr).length(); if (lenOld == 0) { throw new System.ArgumentException(); } int idx1 = str.indexOf(oldStr, 0); if (idx1 == -1) { return((string)(object)str); } int idx0 = 0; int len = str.length(); var sb = new java.lang.StringBuilder(); for (;;) { sb.append(str.substring(idx0, idx1)); if (newStr != null) { sb.append(newStr); } if ((idx0 = idx1 + lenOld) >= len || (idx1 = str.indexOf(oldStr, idx0)) == -1) { sb.append(str.substring(idx0)); return(sb.ToString()); } } }
static void ThrowIfBadIndexOrCount(java.lang.String str, int idx, int num) { if (idx < 0 || num < 0 || idx + num > str.length()) { throw new System.ArgumentOutOfRangeException(); } }
// // throw helpers // static void ThrowIfBadIndex(java.lang.String str, int idx) { if (idx < 0 || idx >= str.length()) { throw new System.ArgumentOutOfRangeException(); } }
// // CopyTo // public static void CopyTo(java.lang.String str, int sourceIndex, char[] destination, int destinationIndex, int count) { ThrowHelper.ThrowIfNull(destination); if (count < 0 || sourceIndex < 0 || destinationIndex < 0 || count > str.length() - sourceIndex || destinationIndex > destination.Length - count) { throw new System.ArgumentOutOfRangeException(); } str.getChars(sourceIndex, sourceIndex + count, destination, destinationIndex); }
public static bool IsNullOrWhiteSpace(java.lang.String str) { if (str != null) { int n = str.length(); for (int i = 0; i < n; i++) { if (!Char.IsWhiteSpace(str.charAt(i))) { return(false); } } } return(true); }
private static int InternalIndexOfAny(java.lang.String str, char[] anyOf, int dir, bool haveStartIndex, int startIndex, bool haveCount, int count) { ThrowHelper.ThrowIfNull(anyOf); int length = str.length(); if (haveCount && count < 0) { throw new System.ArgumentOutOfRangeException(); } int endIndex; if (dir == 1) { // IndexOfAny endIndex = haveCount ? (startIndex + count) : length; if (startIndex < 0 || endIndex > length) { throw new System.ArgumentOutOfRangeException(); } } else { // LastIndexOfAny if (!haveStartIndex) { startIndex = length - 1; } endIndex = haveCount ? (startIndex - count + 1) : 0; if (endIndex < 0 || startIndex >= length) { throw new System.ArgumentOutOfRangeException(); } } for (int index = startIndex; index != endIndex; index += dir) { if (CharAtIsAnyOf(str, index, anyOf)) { return(index); } } return(-1); }
public static string TrimWhiteSpace(java.lang.String str, bool trimStart, bool trimEnd) { int n = str.length(); int i = 0; if (trimStart) { while (i < n && Char.IsWhiteSpace(str.charAt(i))) { i++; } } if (trimEnd) { while (n-- > i && Char.IsWhiteSpace(str.charAt(n))) { ; } n++; } return(str.substring(i, n)); }
private static string[] InternalSplit(java.lang.String str, object separator, int count, System.StringSplitOptions options) { if (count < 0) { throw new System.ArgumentOutOfRangeException(); } bool omit = (options == System.StringSplitOptions.None) ? false : (options == System.StringSplitOptions.RemoveEmptyEntries) ? true : throw new System.ArgumentException(); var emptyArray = new string[0]; if (count == 0) { return(emptyArray); } int length = str.length(); var list = new java.util.ArrayList(); if (separator is char[] charSeparator) { SplitCharacter(str, length, list, count, omit, charSeparator); } else if (separator is java.lang.String[] strSeparator) { SplitString(str, length, list, count, omit, strSeparator); } else // assuming separator is null { SplitWhiteSpace(str, length, list, count, omit); } return((string[])list.toArray(emptyArray)); }
public JavaCharEnumerator(javaString str) { this.str = str; this.index = -1; this.length = str.length(); }
public static string FormatNumber(java.lang.String format, IFormatProvider provider, java.lang.Number number) { if (provider != null) { if ((provider is System.Globalization.NumberFormatInfo) || null != provider.GetFormat( typeof(System.Globalization.NumberFormatInfo))) { throw new PlatformNotSupportedException("provider with a NumberFormatInfo"); } } int len = format.length(); bool explicit_width = false; int width = -1; if (len == 1) { width = 0; } else if (len > 1 && len <= 3) { int n10 = 0; int n01 = (int)(format.charAt(1) - '0'); if (len > 2) { n10 = n01; n01 = (int)(format.charAt(2) - '0'); } if (n01 >= 0 && n01 <= 9 && n10 >= 0 && n10 <= 9) { width = n10 * 10 + n01; } } char c = format.charAt(0); bool isInt = (number is java.lang.Byte || number is java.lang.Short || number is java.lang.Integer || number is java.lang.Long); char pfx = (char)0; string sfx = ""; switch (Char.ToUpperInvariant(c)) { case 'X': if (width != 0) { pfx = '0'; } if (!isInt) { c = (char)0; } else if (number is java.lang.Byte) { number = java.lang.Integer.valueOf(number.byteValue() & 0xFF); } else if (number is java.lang.Short) { number = java.lang.Integer.valueOf(number.shortValue() & 0xFFFF); } break; case 'D': c = isInt ? 'd' : (char)0; pfx = '0'; break; case 'N': if (isInt) { c = 'd'; sfx = "." + new string('0', width); width = 0; } else { c = 'f'; explicit_width = true; // set width even if zero } pfx = ','; break; case 'P': number = java.lang.Double.valueOf(number.doubleValue() * 100.0); pfx = ','; sfx = "%%"; if (len == 1) { width = 2; } goto case 'F'; case 'F': c = 'f'; goto case 'G'; case 'E': case 'G': if (isInt) { number = java.lang.Double.valueOf(number.doubleValue()); isInt = false; } break; default: c = (char)0; break; } if (c != 0 && width != -1) { var format1 = "%"; if (pfx != 0) { format1 += pfx; } if (explicit_width || width != 0) { if (!isInt) { format1 += "."; } format1 += width.ToString(); } format1 += c + sfx; return(java.lang.String.format(format1, new object[] { number })); } return((string)(object)format); }
public static bool IsNullOrEmpty(java.lang.String str) => (str == null || str.length() == 0);
// // // public static int get_Length(java.lang.String str) => str.length();