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


C# String.length方法代码示例

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


在下文中一共展示了String.length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: getDirectoryName

		public static String getDirectoryName(String path) {
			if (path != null) {
				int index = path.lastIndexOf(DIRECTORY_SEPARATOR_CHAR);
				int index2 = path.lastIndexOf(ALT_DIRECTORY_SEPARATOR_CHAR);
				if (index2 > index) {
					index = index2;
				}
				if (index != -1) {
					if (index == path.length() - 1) {
						if (path.indexOf(VOLUME_SEPARATOR_CHAR) == index - 1) {
							return null;
						} else {
							path = path.substring(0, index);
						}
					} else {
						if (path.indexOf(VOLUME_SEPARATOR_CHAR) == index - 1) {
							path = path.substring(0, index + 1);
						} else {
							path = path.substring(0, index);
						}
					}
					if (path.length() == 2 && path[1] == VOLUME_SEPARATOR_CHAR) {
						return "";
					}
				}
				return path;
			}
			return null;
		}
开发者ID:nagyistoce,项目名称:cnatural-language,代码行数:29,代码来源:PathHelper.stab.cs

示例2: writeFloat

 /*
 public void writeFloat(float v) {
 writeInt(Float.floatToIntBits(v));
 }
 public void writeDouble(double v) {
 writeLong(Double.doubleToLongBits(v));
 }
 */
 public void writeBytes(String s)
 {
     int len = s.length();
     for (int i = 0 ; i < len ; i++) {
     @out.write((byte)s.charAt(i));
     }
     incCount(len);
 }
开发者ID:jason-persson,项目名称:LibPhoneNumberPortable,代码行数:16,代码来源:DataOutputStream.cs

示例3: quoteReplacement

 public static String quoteReplacement(String s)
 {
     if ((s.indexOf('\\') == -1) && (s.indexOf('$') == -1))
     return s;
     StringBuilder sb = new StringBuilder();
     for (int i=0; i<s.length(); i++) {
     char c = s.charAt(i);
     if (c == '\\' || c == '$') {
         sb.append('\\');
     }
     sb.append(c);
     }
     return sb.toString();
 }
开发者ID:jason-persson,项目名称:LibPhoneNumberPortable,代码行数:14,代码来源:Matcher.cs

示例4: decodeHexadecimalLong

 public static long decodeHexadecimalLong(String value) {
     long result = 0;
     var ndigits = 0;
     for (var i = 2; i < value.length(); i++) {
         var digit = ParserHelper.scanHexDigit(value[i]);
         if (ndigits == 0 && digit == 0) {
             continue;
         }
         result <<= 4;
         result |= digit;
         if (++ndigits == 17) {
             throw new NumberFormatException(value);
         }
     }
     return result;
 }
开发者ID:nagyistoce,项目名称:cnatural-language,代码行数:16,代码来源:ParserHelper.stab.cs

示例5: hasExtension

		public static bool hasExtension(String path) {
			int index = path.lastIndexOf('.');
			if (index == -1) {
				return false;
			}
			return (index + 1) != path.length();
		}
开发者ID:nagyistoce,项目名称:cnatural-language,代码行数:7,代码来源:PathHelper.stab.cs

示例6: narrowDownPossibleFormats

 private void narrowDownPossibleFormats(String leadingDigits)
 {
     int indexOfLeadingDigitsPattern = leadingDigits.length() - MIN_LEADING_DIGITS_LENGTH;
     Iterator<NumberFormat> it = possibleFormats.iterator();
     while (it.hasNext()) {
       NumberFormat format = it.next();
       if (format.leadingDigitsPatternSize() > indexOfLeadingDigitsPattern) {
     Pattern leadingDigitsPattern =
     regexCache.getPatternForRegex(
         format.getLeadingDigitsPattern(indexOfLeadingDigitsPattern));
     Matcher m = leadingDigitsPattern.matcher(leadingDigits);
     if (!m.lookingAt()) {
       it.remove();
     }
       } // else the particular format has no more specific leadingDigitsPattern, and it should be
     // retained.
     }
 }
开发者ID:jason-persson,项目名称:LibPhoneNumberPortable,代码行数:18,代码来源:AsYouTypeFormatter.cs

示例7: isNullOrEmpty

		public static bool isNullOrEmpty(String str) {
			return str == null || str.length() == 0;
		}
开发者ID:nagyistoce,项目名称:cnatural-language,代码行数:3,代码来源:Helper.stab.cs

示例8: doTestInContext

        private void doTestInContext(String number, String defaultCountry,
      List<NumberContext> contextPairs, Leniency leniency)
        {
            foreach(NumberContext context in contextPairs) {
              String prefix = context.leadingText;
              String text = prefix + number + context.trailingText;

              int start = prefix.length();
              int end = start + number.length();
              Iterator<PhoneNumberMatch> iterator =
              phoneUtil.findNumbers(text, defaultCountry, leniency, Long.MAX_VALUE).iterator();

              PhoneNumberMatch match = iterator.hasNext() ? iterator.next() : null;
              assertNotNull("Did not find a number in '" + text + "'; expected '" + number + "'", match);

              CharSequence extracted = text.subSequence(match.start(), match.end());
              assertTrue("Unexpected phone region in '" + text + "'; extracted '" + extracted + "'",
              start == match.start() && end == match.end());
              assertTrue(number.contentEquals(extracted));
              assertTrue(match.rawString().contentEquals(extracted));

              ensureTermination(text, defaultCountry, leniency);
            }
        }
开发者ID:jason-persson,项目名称:LibPhoneNumberPortable,代码行数:24,代码来源:PhoneNumberMatcherTest.cs

示例9: writeLongUTF

 /*
 void writeLongUTF(String s) {
 writeLongUTF(s, getUTFLength(s));
 }
 internal void writeLongUTF(String s, long utflen) {
 writeLong(utflen);
 if (utflen == (long) s.length()) {
     writeBytes(s);
 } else {
     writeUTFBody(s);
 }
 }
 */
 private void writeUTFBody(String s)
 {
     int limit = MAX_BLOCK_SIZE - 3;
     int len = s.length();
     for (int off = 0; off < len; ) {
     int csize = Math.min(len - off, CHAR_BUF_SIZE);
     s.getChars(off, off + csize, cbuf, 0);
     for (int cpos = 0; cpos < csize; cpos++) {
         char c = cbuf[cpos];
         if (pos <= limit) {
             if (c <= 0x007F && c != 0) {
                 buf[pos++] = (byte) c;
             } else if (c > 0x07FF) {
                 buf[pos + 2] = (byte) (0x80 | ((c >> 0) & 0x3F));
                 buf[pos + 1] = (byte) (0x80 | ((c >> 6) & 0x3F));
                 buf[pos + 0] = (byte) (0xE0 | ((c >> 12) & 0x0F));
                 pos += 3;
             } else {
                 buf[pos + 1] = (byte) (0x80 | ((c >> 0) & 0x3F));
                 buf[pos + 0] = (byte) (0xC0 | ((c >> 6) & 0x1F));
                 pos += 2;
             }
         } else {    // write one byte at a time to normalize block
             if (c <= 0x007F && c != 0) {
                 write(c);
             } else if (c > 0x07FF) {
                 write(0xE0 | ((c >> 12) & 0x0F));
                 write(0x80 | ((c >> 6) & 0x3F));
                 write(0x80 | ((c >> 0) & 0x3F));
             } else {
                 write(0xC0 | ((c >> 6) & 0x1F));
                 write(0x80 | ((c >> 0) & 0x3F));
             }
         }
     }
     off += csize;
     }
 }
开发者ID:jason-persson,项目名称:LibPhoneNumberPortable,代码行数:51,代码来源:ObjectOutputStream.cs

示例10: writeUTF

 static int writeUTF(String str, DataOutputStream @out)
 {
     int strlen = str.length();
     int utflen = 0;
     int c, count = 0;
     /* use charAt instead of copying String to char array */
     int i;
     for (i = 0; i < strlen; i++) {
     c = str.charAt(i);
     if ((c >= 0x0001) && (c <= 0x007F)) {
         utflen++;
     } else if (c > 0x07FF) {
         utflen += 3;
     } else {
         utflen += 2;
     }
     }
     if (utflen > 65535)
     throw new Exception(
         "encoded string too long: " + utflen + " bytes");
     byte[] bytearr = null;
     if (@out is DataOutputStream) {
     DataOutputStream dos = (DataOutputStream)@out;
     if(dos.bytearr == null || (dos.bytearr.Length < (utflen+2)))
         dos.bytearr = new byte[(utflen*2) + 2];
     bytearr = dos.bytearr;
     } else {
     bytearr = new byte[utflen+2];
     }
     bytearr[count++] = (byte) ((int)(((uint)utflen) >> 8) & 0xFF);
     bytearr[count++] = (byte) ((int)(((uint)utflen) >> 0) & 0xFF);
     i=0;
     for (i=0; i<strlen; i++) {
        c = str.charAt(i);
        if (!((c >= 0x0001) && (c <= 0x007F))) break;
        bytearr[count++] = (byte) c;
     }
     for (;i < strlen; i++){
     c = str.charAt(i);
     if ((c >= 0x0001) && (c <= 0x007F)) {
         bytearr[count++] = (byte) c;
     } else if (c > 0x07FF) {
         bytearr[count++] = (byte) (0xE0 | ((c >> 12) & 0x0F));
         bytearr[count++] = (byte) (0x80 | ((c >>  6) & 0x3F));
         bytearr[count++] = (byte) (0x80 | ((c >>  0) & 0x3F));
     } else {
         bytearr[count++] = (byte) (0xC0 | ((c >>  6) & 0x1F));
         bytearr[count++] = (byte) (0x80 | ((c >>  0) & 0x3F));
     }
     }
     @out.write(bytearr, 0, utflen+2);
     return utflen + 2;
 }
开发者ID:jason-persson,项目名称:LibPhoneNumberPortable,代码行数:53,代码来源:DataOutputStream.cs

示例11: findBestMatchingLanguageCode

        private String findBestMatchingLanguageCode(
      Set<String> setOfLangs, String language, String script, String region)
        {
            StringBuilder fullLocale = constructFullLocale(language, script, region);
            String fullLocaleStr = fullLocale.toString();
            String normalizedLocale = LOCALE_NORMALIZATION_MAP.get(fullLocaleStr);
            if (normalizedLocale != null) {
              if (setOfLangs.contains(normalizedLocale)) {
            return normalizedLocale;
              }
            }
            if (setOfLangs.contains(fullLocaleStr)) {
              return fullLocaleStr;
            }

            if (onlyOneOfScriptOrRegionIsEmpty(script, region)) {
              if (setOfLangs.contains(language)) {
            return language;
              }
            } else if (script.length() > 0 && region.length() > 0) {
              StringBuilder langWithScript = new StringBuilder(language).append('_').append(script);
              String langWithScriptStr = langWithScript.toString();
              if (setOfLangs.contains(langWithScriptStr)) {
            return langWithScriptStr;
              }

              StringBuilder langWithRegion = new StringBuilder(language).append('_').append(region);
              String langWithRegionStr = langWithRegion.toString();
              if (setOfLangs.contains(langWithRegionStr)) {
            return langWithRegionStr;
              }

              if (setOfLangs.contains(language)) {
            return language;
              }
            }
            return "";
        }
开发者ID:jason-persson,项目名称:LibPhoneNumberPortable,代码行数:38,代码来源:MappingFileProvider.cs

示例12: producePermutations

    private String[] producePermutations(String input) {
        if (input.length() == countChars(input, 0, 1))
            return new String[] {input};
        if (input.length() == countChars(input, 0, 2)) {
            int c0 = Character.codePointAt(input, 0);
            int c1 = Character.codePointAt(input, Character.charCount(c0));
            if (getClass(c1) == getClass(c0)) {
                return new String[] {input};
            }
            String[] result = new String[2];
            result[0] = input;
            StringBuilder sb = new StringBuilder(2);
            sb.appendCodePoint(c1);
            sb.appendCodePoint(c0);
            result[1] = sb.toString();
            return result;
        }
        int length = 1;
        int nCodePoints = countCodePoints(input);
        for(int x=1; x<nCodePoints; x++)
            length = length * (x+1);
        String[] temp = new String[length];
        int[] combClass = new int[nCodePoints];
        for(int x=0, i=0; x<nCodePoints; x++) {
            int c = Character.codePointAt(input, i);
            combClass[x] = getClass(c);
            i +=  Character.charCount(c);
        }
        // For each char, take it out and add the permutations
        // of the remaining chars
        int index = 0;
        int len;
        // offset maintains the index in code units.
        for(int x=0, offset=0; x<nCodePoints; x++, offset+=len) {
continue1:
            len = countChars(input, offset, 1);
            boolean skip = false;
            for(int y=x-1; y>=0; y--) {
                if (combClass[y] == combClass[x]) {
                    offset+=len;
                    if (x < nCodePoints) goto continue1;
                    goto end1;
                }
            }
            StringBuilder sb = new StringBuilder(input);
            String otherChars = sb.delete(offset, offset+len).toString();
            String[] subResult = producePermutations(otherChars);
            String prefix = input.substring(offset, offset+len);
            for(int y=0; y<subResult.Length; y++)
                temp[index++] =  prefix + subResult[y];
        }
end1:
        String[] _result = new String[index];
        for (int x=0; x<index; x++)
            _result[x] = temp[x];
        return _result;
    }
开发者ID:jason-persson,项目名称:LibPhoneNumberPortable,代码行数:57,代码来源:Pattern.cs

示例13: writeChars

 public void writeChars(String s)
 {
     int len = s.length();
     for (int i = 0 ; i < len ; i++) {
     int v = s.charAt(i);
     @out.write((int)(((uint)v) >> 8) & 0xFF);
     @out.write((int)(((uint)v) >> 0) & 0xFF);
     }
     incCount(len * 2);
 }
开发者ID:jason-persson,项目名称:LibPhoneNumberPortable,代码行数:10,代码来源:DataOutputStream.cs

示例14: normalize

 private void normalize() {
     boolean inCharClass = false;
     int lastCodePoint = -1;
     // Convert pattern into normalizedD form
     normalizedPattern = Normalizer.normalize(pattern, Normalizer.Form.NFD);
     patternLength = normalizedPattern.length();
     // Modify pattern to match canonical equivalences
     StringBuilder newPattern = new StringBuilder(patternLength);
     for(int i=0; i<patternLength; ) {
         int c = normalizedPattern.codePointAt(i);
         StringBuilder sequenceBuffer;
         if ((Character.getType(c) == Character.NON_SPACING_MARK)
             && (lastCodePoint != -1)) {
             sequenceBuffer = new StringBuilder();
             sequenceBuffer.appendCodePoint(lastCodePoint);
             sequenceBuffer.appendCodePoint(c);
             while(Character.getType(c) == Character.NON_SPACING_MARK) {
                 i += Character.charCount(c);
                 if (i >= patternLength)
                     break;
                 c = normalizedPattern.codePointAt(i);
                 sequenceBuffer.appendCodePoint(c);
             }
             String ea = produceEquivalentAlternation(
                                            sequenceBuffer.toString());
             newPattern.setLength(newPattern.length()-Character.charCount(lastCodePoint));
             newPattern.append("(?:").append(ea).append(")");
         } else if (c == '[' && lastCodePoint != '\\') {
             i = normalizeCharClass(newPattern, i);
         } else {
             newPattern.appendCodePoint(c);
         }
         lastCodePoint = c;
         i += Character.charCount(c);
     }
     normalizedPattern = newPattern.toString();
 }
开发者ID:jason-persson,项目名称:LibPhoneNumberPortable,代码行数:37,代码来源:Pattern.cs

示例15: produceEquivalentAlternation

 private String produceEquivalentAlternation(String source) {
     int len = countChars(source, 0, 1);
     if (source.length() == len)
         // source has one character.
         return source;
     String @base = source.substring(0,len);
     String combiningMarks = source.substring(len);
     String[] perms = producePermutations(combiningMarks);
     StringBuilder result = new StringBuilder(source);
     // Add combined permutations
     for(int x=0; x<perms.Length; x++) {
         String next = @base + perms[x];
         if (x>0)
             result.append("|"+next);
         next = composeOneStep(next);
         if (next != null)
             result.append("|"+produceEquivalentAlternation(next));
     }
     return result.toString();
 }
开发者ID:jason-persson,项目名称:LibPhoneNumberPortable,代码行数:20,代码来源:Pattern.cs


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