本文整理汇总了C#中String.LastIndexOf方法的典型用法代码示例。如果您正苦于以下问题:C# String.LastIndexOf方法的具体用法?C# String.LastIndexOf怎么用?C# String.LastIndexOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类String
的用法示例。
在下文中一共展示了String.LastIndexOf方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConvertBackTickNameToNameWithReducerInputFormat
public static String ConvertBackTickNameToNameWithReducerInputFormat(String typename, List<int> genericParameterOffsets)
{
int indexOfBackTick = typename.LastIndexOf('`');
if (indexOfBackTick != -1)
{
string typeNameSansBackTick = typename.Substring(0, indexOfBackTick);
if ((indexOfBackTick + 1) < typename.Length)
{
string textAfterBackTick = typename.Substring(indexOfBackTick + 1);
int genericParameterCount;
if (Int32.TryParse(textAfterBackTick, out genericParameterCount) && (genericParameterCount > 0))
{
// Replace the `Number with <,,,> where the count of ',' is one less than Number.
StringBuilder genericTypeName = new StringBuilder();
genericTypeName.Append(typeNameSansBackTick);
genericTypeName.Append('<');
if (genericParameterOffsets != null)
{
genericParameterOffsets.Add(genericTypeName.Length);
}
for (int i = 1; i < genericParameterCount; i++)
{
genericTypeName.Append(',');
if (genericParameterOffsets != null)
{
genericParameterOffsets.Add(genericTypeName.Length);
}
}
genericTypeName.Append('>');
return genericTypeName.ToString();
}
}
}
return typename;
}
示例2: GetDirectory
internal static String GetDirectory(String path)
{
if (path == null || path.Length == 0)
{
throw new ArgumentException(SR.GetString(SR.UrlPath_EmptyPathHasNoDirectory));
}
if (path[0] != '/' && path[0] != appRelativeCharacter)
{
throw new ArgumentException(SR.GetString(SR.UrlPath_PathMustBeRooted));
}
// Make sure there is a filename after the last '/'
Debug.Assert(path[path.Length-1] != '/', "Path should not end with a /");
string dir = path.Substring(0, path.LastIndexOf('/'));
// If it's the root dir, we would end up with "". Return "/" instead
if (dir.Length == 0)
{
return "/";
}
return dir;
}
示例3: BindingMemberInfo
// Constructor.
public BindingMemberInfo(String dataMember)
{
if(dataMember == null)
{
dataMember = String.Empty;
}
int index = dataMember.LastIndexOf('.');
if(index != -1)
{
field = dataMember.Substring(index + 1);
path = dataMember.Substring(0, index);
}
else
{
field = dataMember;
path = String.Empty;
}
fieldType = null;
}
示例4: Unquote
internal static string Unquote (String str) {
int start = str.IndexOf ('\"');
int end = str.LastIndexOf ('\"');
if (start >= 0 && end >=0)
str = str.Substring (start + 1, end - 1);
return str.Trim ();
}
示例5: URTComplexType
internal URTComplexType(String name, String urlNS, String ns, String encodedNS,
SchemaBlockType blockDefault, bool bSUDSType, bool bAnonymous, WsdlParser parser, URTNamespace xns)
: base(name, urlNS, ns, encodedNS)
{
Util.Log("URTComplexType.URTComplexType name "+this.GetHashCode()+" "+name+" urlNS "+urlNS+" ns "+ns+" encodedNS "+encodedNS+" bSUDStype "+bSUDSType+" bAnonymous "+bAnonymous);
_baseTypeName = null;
_baseTypeXmlNS = null;
_baseType = null;
_connectURLs = null;
_bStruct = !bSUDSType;
_blockType = blockDefault;
_bSUDSType = bSUDSType;
_bAnonymous = bAnonymous;
Debug.Assert(bAnonymous == false || _bSUDSType == false);
_fieldString = null;
_fields = new ArrayList();
_methods = new ArrayList();
_implIFaces = new ArrayList();
_implIFaceNames = new ArrayList();
_sudsType = SUDSType.None;
_parser = parser;
int index = name.IndexOf('+');
if (index > 0)
{
// Nested type see if outer type has been added to namespace
String outerType = parser.Atomize(name.Substring(0,index));
URTComplexType cs = xns.LookupComplexType(outerType);
if (cs == null)
{
URTComplexType newCs = new URTComplexType(outerType, urlNS, ns, encodedNS, blockDefault, bSUDSType, bAnonymous, parser, xns);
Util.Log("URTComplexType.URTComplexType add outerType to namespace "+outerType+" nestedname "+name);
xns.AddComplexType(newCs);
}
}
if (xns.UrtType == UrtType.Interop)
{
// Interop class names can have '.', replace these with '_', and set wire name to original type name.
index = name.LastIndexOf('.');
if (index > -1)
{
// class names can't have '.' so replace with '$'. Use xmlType attribute to send original name on wire.
_wireType = name;
Name = name.Replace(".", "_");
SearchName = name;
}
}
}
示例6: VerifyToString
private static void VerifyToString(String test, String format, IFormatProvider provider, bool expectError, String expectedResult)
{
bool hasFormat = !String.IsNullOrEmpty(format);
bool hasProvider = provider != null;
string result = null;
try
{
if (hasFormat)
{
result = hasProvider ? BigInteger.Parse(test, provider).ToString(format, provider) :
BigInteger.Parse(test).ToString(format);
}
else
{
result = hasProvider ? BigInteger.Parse(test, provider).ToString(provider) :
BigInteger.Parse(test).ToString();
}
Assert.False(expectError, "Expected exception not encountered.");
if (expectedResult != result)
{
Assert.Equal(expectedResult.Length, result.Length);
int index = expectedResult.LastIndexOf("E", StringComparison.OrdinalIgnoreCase);
Assert.False(index == 0, "'E' found at beginning of expectedResult");
bool equal = false;
if (index > 0)
{
var dig1 = (byte)expectedResult[index - 1];
var dig2 = (byte)result[index - 1];
equal |= (dig2 == dig1 - 1 || dig2 == dig1 + 1);
equal |= (dig1 == '9' && dig2 == '0' || dig2 == '9' && dig1 == '0');
equal |= (index == 1 && (dig1 == '9' && dig2 == '1' || dig2 == '9' && dig1 == '1'));
}
Assert.True(equal);
}
else
{
Assert.Equal(expectedResult, result);
}
}
catch (Exception e)
{
Assert.True(expectError && e.GetType() == typeof(FormatException), "Unexpected Exception:" + e);
}
}
示例7: GetFileNameWithoutExtension
private static String GetFileNameWithoutExtension(String path)
{
path = GetFileName(path);
int i;
if ((i = path.LastIndexOf('.')) == -1)
return path; // No path extension found
else
return path.Substring(0, i);
}
示例8: HTTPResponse
public HTTPResponse(ByteReader br, TextReader tr, String fileName)
: this()
{
KeyValuePair<string, ContentReader> reader = contentTypes[
fileName.Substring(fileName.LastIndexOf('.')).ToLower()];
attributes.Add("Content-Type", reader.Key);
reader.Value(br, tr, fileName, ref attributes, this);
}
示例9: LastIndexOf
public unsafe virtual int LastIndexOf(String source, char value, int startIndex, int count, CompareOptions options)
{
// Verify Arguments
if (source == null)
throw new ArgumentNullException(nameof(source));
Contract.EndContractBlock();
// Validate CompareOptions
// Ordinal can't be selected with other flags
if ((options & ValidIndexMaskOffFlags) != 0 &&
(options != CompareOptions.Ordinal) &&
(options != CompareOptions.OrdinalIgnoreCase))
throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options));
// Special case for 0 length input strings
if (source.Length == 0 && (startIndex == -1 || startIndex == 0))
return -1;
// Make sure we're not out of range
if (startIndex < 0 || startIndex > source.Length)
throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index);
// Make sure that we allow startIndex == source.Length
if (startIndex == source.Length)
{
startIndex--;
if (count > 0)
count--;
}
// 2nd have of this also catches when startIndex == MAXINT, so MAXINT - 0 + 1 == -1, which is < 0.
if (count < 0 || startIndex - count + 1 < 0)
throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Count);
if (options == CompareOptions.OrdinalIgnoreCase)
{
return source.LastIndexOf(value.ToString(), startIndex, count, StringComparison.OrdinalIgnoreCase);
}
return LastIndexOfCore(source, value.ToString(), startIndex, count, options);
}
示例10: LoadFile
public void LoadFile(String file)
{
FileName = file;
FileNameShort = FileName.Substring(FileName.LastIndexOf('\\')+1);
}
示例11: GetDirectory
internal static String GetDirectory(String path) {
if (String.IsNullOrEmpty(path))
throw new ArgumentException(SR.GetString(SR.Empty_path_has_no_directory));
if (path[0] != '/' && path[0] != appRelativeCharacter)
throw new ArgumentException(SR.GetString(SR.Path_must_be_rooted, path));
// If it's just "~" or "/", return it unchanged
if (path.Length == 1)
return path;
int slashIndex = path.LastIndexOf('/');
// This could happen if the input looks like "~abc"
if (slashIndex < 0)
throw new ArgumentException(SR.GetString(SR.Path_must_be_rooted, path));
return path.Substring(0, slashIndex + 1);
}
示例12: Combine
private static String Combine(String appPath, String basepath, String relative) {
String path;
if (String.IsNullOrEmpty(relative))
throw new ArgumentNullException("relative");
if (String.IsNullOrEmpty(basepath))
throw new ArgumentNullException("basepath");
if (basepath[0] == appRelativeCharacter && basepath.Length == 1) {
// If it's "~", change it to "~/"
basepath = appRelativeCharacterString;
}
else {
// If the base path includes a file name, get rid of it before combining
int lastSlashIndex = basepath.LastIndexOf('/');
Debug.Assert(lastSlashIndex >= 0);
if (lastSlashIndex < basepath.Length - 1) {
basepath = basepath.Substring(0, lastSlashIndex + 1);
}
}
// Make sure it's a virtual path (ASURT 73641)
CheckValidVirtualPath(relative);
if (IsRooted(relative)) {
path = relative;
}
else {
// If the path is exactly "~", just return the app root path
if (relative.Length == 1 && relative[0] == appRelativeCharacter)
return appPath;
// If the relative path starts with "~/" or "~\", treat it as app root
// relative (ASURT 68628)
if (IsAppRelativePath(relative)) {
if (appPath.Length > 1)
path = appPath + "/" + relative.Substring(2);
else
path = "/" + relative.Substring(2);
} else {
path = SimpleCombine(basepath, relative);
}
}
return Reduce(path);
}