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


C# String.substring方法代码示例

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


在下文中一共展示了String.substring方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getFileName

		public static String getFileName(String path) {
			if (path != null) {
				int index = path.lastIndexOf(DIRECTORY_SEPARATOR_CHAR);
				if (index == -1) {
					index = path.lastIndexOf(ALT_DIRECTORY_SEPARATOR_CHAR);
				}
				if (index == -1) {
					return path;
				}
				return path.substring(index + 1);
			}
			return null;
		}
开发者ID:nagyistoce,项目名称:cnatural-language,代码行数:13,代码来源:PathHelper.stab.cs

示例3: getFileNameWithoutExtension

		public static String getFileNameWithoutExtension(String path) {
			if (path != null) {
				int index = path.lastIndexOf(DIRECTORY_SEPARATOR_CHAR);
				if (index == -1) {
					index = path.lastIndexOf(ALT_DIRECTORY_SEPARATOR_CHAR);
				}
				if (index != -1) {
					path = path.substring(index + 1);
				}
				index = path.lastIndexOf('.');
				if (index == -1) {
					return path;
				}
				return path.substring(0, index);
			}
			return null;
		}
开发者ID:nagyistoce,项目名称:cnatural-language,代码行数:17,代码来源:PathHelper.stab.cs

示例4: getTypeInfo

 private TypeInfo getTypeInfo(String name) {
     int idx = name.indexOf('$');
     if (idx == -1) {
         return typeSystem.getType(name);
     }
     var type = typeSystem.getType(name.substring(0, idx));
     name = name.substring(idx + 1);
     while ((idx = name.indexOf('$')) != -1) {
         type = type.getNestedType(name.substring(0, idx));
         name = name.substring(idx + 1);
     }
     return type;
 }
开发者ID:nagyistoce,项目名称:cnatural-language,代码行数:13,代码来源:TypeBuilder.stab.cs

示例5: getType

 private TypeInfo getType(String name) {
     name = name.trim();
     int dimensions = 0;
     while (name.endsWith("[]")) {
         dimensions++;
         name = name.substring(0, name.length() - 2);
     }
     TypeInfo result;
     switch (name) {
     case "boolean":
         result = context.TypeSystem.BooleanType;
         break;
     case "byte":
         result = context.TypeSystem.ByteType;
         break;
     case "char":
         result = context.TypeSystem.CharType;
         break;
     case "short":
         result = context.TypeSystem.ShortType;
         break;
     case "int":
         result = context.TypeSystem.IntType;
         break;
     case "long":
         result = context.TypeSystem.LongType;
         break;
     case "float":
         result = context.TypeSystem.FloatType;
         break;
     case "double":
         result = context.TypeSystem.DoubleType;
         break;
     default:
         int idx = name.indexOf(".");
         String prefix;
         if (idx == -1) {
             prefix = name;
             name = null;
         } else {
             prefix = name.substring(0, idx);
             name = name.substring(idx + 1);
         }
         var members = context.MemberResolver.resolveName(context.CurrentType, prefix, Query.empty<TypeInfo>()).toList();
         if (!members.any()) {
             if (name == null) {
                 return null;
             }
             var packageName = context.MemberResolver.getPackageFromAlias(prefix);
             if (packageName == null) {
                 if (context.MemberResolver.TypeFinder.getSubPackages(prefix).any()
                  || context.MemberResolver.TypeFinder.getClasses(prefix).any()) {
                     packageName = prefix;
                 } else {
                     return null;
                 }
             }
             var found = false;
             do {
                 idx = name.indexOf('.');
                 if (idx == -1) {
                     prefix = name;
                     name = null;
                 } else {
                     prefix = name.substring(0, idx);
                     name = name.substring(idx + 1);
                 }
                 foreach (var s in context.MemberResolver.TypeFinder.getSubPackages(packageName)) {
                     if (s.equals(prefix)) {
                         packageName = packageName + '/' + prefix;
                         found = true;
                         break;
                     }
                 }
                 if (!found && !context.MemberResolver.TypeFinder.getClasses(packageName).contains(prefix)) {
                     return null;
                 }
             } while (name != null && found);
             result = context.TypeSystem.getType(packageName + '/' + prefix);
         } else if (members.count() > 1) {
             return null;
         } else {
             result = members.first().Type;
         }
         break;
     }
     while (dimensions-- > 0) {
         type = type.ArrayType;
     }
     return result;
 }
开发者ID:nagyistoce,项目名称:cnatural-language,代码行数:91,代码来源:DocumentationBuilder.stab.cs

示例6: replaceCref

 private void replaceCref(Element element, bool exception, Iterable<MemberInfo> members, String suffix, String arguments) {
     if (members.count() > 1 && !members.all(p => p.MemberKind == MemberKind.Method)) {
         context.addWarning(CompileErrorId.UnresolvedCref, node, element.getAttribute("cref"));
         element.setAttribute("cref", "!" + element.getAttribute("cref"));
         return;
     }
     var member = members.first();
     switch (member.MemberKind) {
     case Type:
         replaceCref(element, exception, member.Type, suffix, arguments);
         break;
     case Field:
         if (exception) {
             context.addWarning(CompileErrorId.ExpectedExceptionInCref, node, element.getAttribute("cref"));
             element.setAttribute("cref", "!" + element.getAttribute("cref"));
             return;
         }
         if (suffix != null || arguments != null) {
             context.addWarning(CompileErrorId.UnresolvedCref, node, element.getAttribute("cref"));
             element.setAttribute("cref", "!" + element.getAttribute("cref"));
             return;
         }
         element.setAttribute("cref", getIdString(member.Field));
         break;
     
     case Property:
         if (exception) {
             context.addWarning(CompileErrorId.ExpectedExceptionInCref, node, element.getAttribute("cref"));
             element.setAttribute("cref", "!" + element.getAttribute("cref"));
             return;
         }
         if (suffix != null || arguments != null) {
             context.addWarning(CompileErrorId.UnresolvedCref, node, element.getAttribute("cref"));
             element.setAttribute("cref", "!" + element.getAttribute("cref"));
             return;
         }
         element.setAttribute("cref", getIdString(member.GetAccessor ?? member.SetAccessor));
         break;
     
     case Method:
         if (!exception && suffix == null) {
             if (arguments == null && members.count() == 1) {
                 element.setAttribute("cref", getIdString(member.Method));
                 return;
             } else if (arguments != null && arguments.endsWith(")")) {
                 var args = new ArrayList<TypeInfo>();
                 if (arguments.length() > 2) {
                     arguments = arguments.substring(1, arguments.length() - 1);
                     int idx;
                     while ((idx = arguments.indexOf(',')) != -1) {
                         var name = arguments.substring(0, idx);
                         arguments = arguments.substring(idx + 1);
                         var type = getType(name);
                         if (type == null) {
                             goto failed;
                         }
                         args.add(type);
                     }
                     if (arguments.length() == 0) {
                         goto failed;
                     }
                     var type = getType(arguments);
                     if (type == null) {
                         goto failed;
                     }
                     args.add(type);
                 }
                 foreach (var m in members) {
                     if (m.Method.Parameters.select(p => p.Type).sequenceEqual(args)) {
                         element.setAttribute("cref", getIdString(m.Method));
                         return;
                     }
                 }
             }
         }
     failed:
         context.addWarning(CompileErrorId.UnresolvedCref, node, element.getAttribute("cref"));
         element.setAttribute("cref", "!" + element.getAttribute("cref"));
         break;
         
     default:
         break;
     }
 }
开发者ID:nagyistoce,项目名称:cnatural-language,代码行数:84,代码来源:DocumentationBuilder.stab.cs

示例7: getExtension

		public static String getExtension(String path) {
			if (path != null) {
				int index = path.lastIndexOf('.');
				if (index == -1) {
					return "";
				}
				return path.substring(index);
			}
			return null;
		}
开发者ID:nagyistoce,项目名称:cnatural-language,代码行数:10,代码来源:PathHelper.stab.cs

示例8: getType

		public static TypeInfo getType(Library typeSystem, String fullName) {
			TypeInfo result = null;
			int index;
			while ((index = fullName.indexOf('$')) != -1) {
				String prefix = fullName.substring(0, index);
				if (result == null) {
					result = typeSystem.getType(prefix);
				} else {
					result = result.getNestedType(prefix);
				}
				fullName = fullName.substring(index + 1);
			}
			if (result == null) {
				result = typeSystem.getType(fullName);
			} else {
				result = result.getNestedType(fullName);
			}
			return result;
		}
开发者ID:nagyistoce,项目名称:cnatural-language,代码行数:19,代码来源:JvmTypeSystemHelper.stab.cs

示例9: composeOneStep

 private String composeOneStep(String input) {
     int len = countChars(input, 0, 2);
     String firstTwoCharacters = input.substring(0, len);
     String result = Normalizer.normalize(firstTwoCharacters, Normalizer.Form.NFC);
     if (result.equals(firstTwoCharacters))
         return null;
     else {
         String remainder = input.substring(len);
         return result + remainder;
     }
 }
开发者ID:jason-persson,项目名称:LibPhoneNumberPortable,代码行数:11,代码来源:Pattern.cs

示例10: 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

示例11: 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

示例12: quote

 public static String quote(String s) {
     int slashEIndex = s.indexOf(new String("\\E"));
     if (slashEIndex == -1)
         return new String("\\Q" + s + "\\E");
     StringBuilder sb = new StringBuilder(s.length() * 2);
     sb.append("\\Q");
     slashEIndex = 0;
     int current = 0;
     while ((slashEIndex = s.indexOf(new String("\\E"), current)) != -1) {
         sb.append(s.substring(current, slashEIndex));
         current = slashEIndex + 2;
         sb.append("\\E\\\\E\\Q");
     }
     sb.append(s.substring(current, s.length()));
     sb.append("\\E");
     return sb.toString();
 }
开发者ID:jason-persson,项目名称:LibPhoneNumberPortable,代码行数:17,代码来源:Pattern.cs

示例13: ensureTermination

 /**
    * Exhaustively searches for phone numbers from each index within {@code text} to test that
    * finding matches always terminates.
    */
 private void ensureTermination(String text, String defaultCountry, Leniency leniency)
 {
     for (int index = 0; index <= text.length(); index++) {
       String sub = text.substring(index);
       StringBuilder matches = new StringBuilder();
       // Iterates over all matches.
       foreach(PhoneNumberMatch match in
        phoneUtil.findNumbers(sub, defaultCountry, leniency, Long.MAX_VALUE)) {
     matches.append(", ").append(match.toString());
       }
     }
 }
开发者ID:jason-persson,项目名称:LibPhoneNumberPortable,代码行数:16,代码来源:PhoneNumberMatcherTest.cs


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