本文整理汇总了C#中java.lang.String.indexOf方法的典型用法代码示例。如果您正苦于以下问题:C# String.indexOf方法的具体用法?C# String.indexOf怎么用?C# String.indexOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.String
的用法示例。
在下文中一共展示了String.indexOf方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: 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();
}
示例3: 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;
}
示例4: 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;
}
示例5: 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;
}
}
示例6: 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;
}
示例7: 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();
}