本文整理汇总了C#中String.IndexOf方法的典型用法代码示例。如果您正苦于以下问题:C# String.IndexOf方法的具体用法?C# String.IndexOf怎么用?C# String.IndexOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类String
的用法示例。
在下文中一共展示了String.IndexOf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Stylesheet
public Stylesheet(String stylesheet)
{
char currentChar = '\0';
StringBuilder buffer = new StringBuilder();
for (int i = 0, j = 0; i < stylesheet.Length; i++, j++)
{
currentChar = stylesheet[i];
switch (currentChar)
{
case ' ':
continue;
case '{':
{
int endIndex = stylesheet.IndexOf('}', i);
String block = stylesheet.Substring(i, endIndex - i);
Selector selector = new Selector(buffer.ToString().Trim(), block);
this.selectors.Add(selector);
i = endIndex - 1;
buffer.Clear();
continue;
}
default:
buffer.Append(currentChar);
break;
}
}
}
示例2: while
// Validate a qualified identifier.
private static void ValidateQualifiedIdentifier
(String value, bool canBeNull)
{
if(value == null)
{
if(!canBeNull)
{
throw new ArgumentException
(S._("Arg_InvalidIdentifier"));
}
}
else
{
int posn = 0;
int index;
String component;
while((index = value.IndexOf('.', posn)) != -1)
{
component = value.Substring(posn, index - posn);
ValidateIdentifier(component);
posn = index + 1;
}
component = value.Substring(posn);
ValidateIdentifier(component);
}
}
示例3: CheckSearchPattern
// ".." can only be used if it is specified as a part of a valid File/Directory name. We disallow
// the user being able to use it to move up directories. Here are some examples eg
// Valid: a..b abc..d
// Invalid: ..ab ab.. .. abc..d\abc..
//
internal static void CheckSearchPattern(String searchPattern)
{
for (int index = 0; (index = searchPattern.IndexOf("..", index, StringComparison.Ordinal)) != -1; index += 2)
{
// Terminal ".." or "..\". File and directory names cannot end in "..".
if (index + 2 == searchPattern.Length ||
IsDirectorySeparator(searchPattern[index + 2]))
{
throw new ArgumentException(SR.Arg_InvalidSearchPattern, "searchPattern");
}
}
}
示例4: AccessingLoginPage
internal static bool AccessingLoginPage(HttpContext context, String loginUrl) {
if (String.IsNullOrEmpty(loginUrl)) {
return false;
}
loginUrl = GetCompleteLoginUrl(context, loginUrl);
if (String.IsNullOrEmpty(loginUrl)) {
return false;
}
// Ignore query string
int iqs = loginUrl.IndexOf('?');
if (iqs >= 0) {
loginUrl = loginUrl.Substring(0, iqs);
}
String requestPath = context.Request.Path;
if (StringUtil.EqualsIgnoreCase(requestPath, loginUrl)) {
return true;
}
// It could be that loginUrl in config was UrlEncoded (ASURT 98932)
if (loginUrl.IndexOf('%') >= 0) {
String decodedLoginUrl;
// encoding is unknown try UTF-8 first, then request encoding
decodedLoginUrl = HttpUtility.UrlDecode(loginUrl);
if (StringUtil.EqualsIgnoreCase(requestPath, decodedLoginUrl)) {
return true;
}
decodedLoginUrl = HttpUtility.UrlDecode(loginUrl, context.Request.ContentEncoding);
if (StringUtil.EqualsIgnoreCase(requestPath, decodedLoginUrl)) {
return true;
}
}
return false;
}
示例5: WebProxy
public WebProxy(String Address)
{
if(Address != null)
{
if(Address.IndexOf("://") == -1)
{
address = new Uri("http://" + Address);
}
else
{
address = new Uri(Address);
}
}
}
示例6: LocateNextSelectedDate
private int LocateNextSelectedDate(String webCalendarHtml, int startingIndex)
{
int tagBeginIndex = startingIndex;
do
{
tagBeginIndex = webCalendarHtml.IndexOf(_selectedDateSearchCellTag, tagBeginIndex, StringComparison.Ordinal);
if (tagBeginIndex >= 0)
{
int tagEndIndex = webCalendarHtml.IndexOf(">", tagBeginIndex + _bgColorInsertionPointInPattern, StringComparison.Ordinal);
Debug.Assert(tagEndIndex >= 0);
String tagComplete = webCalendarHtml.Substring(tagBeginIndex, tagEndIndex-tagBeginIndex+1);
if (tagComplete.IndexOf(_selectedDateSearchAttr, StringComparison.Ordinal) >= 0)
{
return tagBeginIndex;
}
else
{
tagBeginIndex += _bgColorInsertionPointInPattern;
}
}
}
while (tagBeginIndex >= 0);
return -1;
}
示例7: SoapFault
internal SoapFault(SerializationInfo info, StreamingContext context)
{
faultCode = info.GetStringIgnoreCase("faultcode");
if(faultCode != null)
{
int posn = faultCode.IndexOf(':');
if(posn != -1)
{
faultCode = faultCode.Substring(posn + 1);
}
}
faultString = info.GetStringIgnoreCase("faultstring");
faultActor = info.GetStringIgnoreCase("faultactor");
serverFault = info.GetValueIgnoreCase("detail", typeof(Object));
}
示例8: ExtractValueFromContentDispositionHeader
private String ExtractValueFromContentDispositionHeader(String l, int pos, String name) {
String pattern = " " + name + "=";
int i1 = CultureInfo.InvariantCulture.CompareInfo.IndexOf(l, pattern, pos, CompareOptions.IgnoreCase);
if (i1 < 0) {
pattern = ";" + name + "=";
i1 = CultureInfo.InvariantCulture.CompareInfo.IndexOf(l, pattern, pos, CompareOptions.IgnoreCase);
if (i1 < 0) {
pattern = name + "=";
i1 = CultureInfo.InvariantCulture.CompareInfo.IndexOf(l, pattern, pos, CompareOptions.IgnoreCase);
}
}
if (i1 < 0)
return null;
i1 += pattern.Length;
if (i1 >= l.Length)
return String.Empty;
if (l[i1] == '"') {
i1 += 1;
int i2 = l.IndexOf('"', i1);
if (i2 < 0)
return null;
if (i2 == i1)
return String.Empty;
return l.Substring(i1, i2-i1);
}
else {
int i2 = l.IndexOf(';', i1);
if (i2 < 0)
i2 = l.Length;
return l.Substring(i1, i2-i1).Trim();
}
}
示例9: sendCommand
/// <summary>
/// sendCommand
/// </summary>
/// <param name="command"></param>
private void sendCommand(String command)
{
int l_iRetval = 0;
if (this.verboseDebugging)
{
if (command.IndexOf("PASS ") >= 0)
{
// don't show password in message area
// show only *
showMessage("PASS [*** hidden ***]", false);
}
else
{
showMessage(command, false);
}
}
try
{
Byte[] cmdBytes = Encoding.ASCII.GetBytes((command.Trim() + "\r\n").ToCharArray());
l_iRetval = clientSocket.Send(cmdBytes, cmdBytes.Length, 0);
this.readResponse();
}
catch (Exception ex)
{
throw new IOException(ex.Message);
}
}
示例10: GetMethodName
private static String GetMethodName(String methodName)
{
int startIndex = methodName.IndexOf(" ") + 1;
int endIndex = methodName.IndexOf("(");
return methodName.Substring(startIndex, endIndex - startIndex);
}
示例11: GetMethodParameters
private static Type[] GetMethodParameters(String methodName)
{
int startIndex = methodName.IndexOf("(") + 1;
int endIndex = methodName.IndexOf(")");
if (endIndex <= startIndex)
return new Type[0];
String[] parameters = methodName.Substring(startIndex, endIndex - startIndex).Split(',');
List<Type> parameterList = new List<Type>();
foreach (String parameter in parameters)
parameterList.Add(Type.GetType(parameter.Trim()));
return parameterList.ToArray();
}
示例12: SetDescription
/*
* SetDescription()
*
* Produces a human-readable description for a set string.
*/
internal static String SetDescription(String set) {
int mySetLength = set[SETLENGTH];
int myCategoryLength = set[CATEGORYLENGTH];
int myEndPosition = SETSTART + mySetLength + myCategoryLength;
StringBuilder desc = new StringBuilder("[");
int index = SETSTART;
char ch1;
char ch2;
if (IsNegated(set))
desc.Append('^');
while (index < SETSTART + set[SETLENGTH]) {
ch1 = set[index];
if (index + 1 < set.Length)
ch2 = (char)(set[index + 1] - 1);
else
ch2 = Lastchar;
desc.Append(CharDescription(ch1));
if (ch2 != ch1) {
if (ch1 + 1 != ch2)
desc.Append('-');
desc.Append(CharDescription(ch2));
}
index += 2;
}
while (index < SETSTART + set[SETLENGTH] + set[CATEGORYLENGTH]) {
ch1 = set[index];
if (ch1 == 0) {
bool found = false;
int lastindex = set.IndexOf(GroupChar, index+1);
string group = set.Substring(index,lastindex-index + 1);
IDictionaryEnumerator en = _definedCategories.GetEnumerator();
while(en.MoveNext()) {
if (group.Equals(en.Value)) {
if ((short) set[index+1] > 0)
desc.Append("\\p{" + en.Key + "}");
else
desc.Append("\\P{" + en.Key + "}");
found = true;
break;
}
}
if (!found) {
if (group.Equals(Word))
desc.Append("\\w");
else if (group.Equals(NotWord))
desc.Append("\\W");
else
Debug.Assert(false, "Couldn't find a goup to match '" + group + "'");
}
index = lastindex;
}
else {
desc.Append(CategoryDescription(ch1));
}
index++;
}
if (set.Length > myEndPosition) {
desc.Append('-');
desc.Append(SetDescription(set.Substring(myEndPosition)));
}
desc.Append(']');
return desc.ToString();
}
示例13: CheckSearchPattern
// ".." can only be used if it is specified as a part of a valid File/Directory name. We disallow
// the user being able to use it to move up directories. Here are some examples eg
// Valid: a..b abc..d
// Invalid: ..ab ab.. .. abc..d\abc..
//
internal static void CheckSearchPattern(String searchPattern)
{
int index;
while ((index = searchPattern.IndexOf("..", StringComparison.Ordinal)) != -1) {
if (index + 2 == searchPattern.Length) // Terminal ".." . Files names cannot end in ".."
throw new ArgumentException(Environment.GetResourceString("Arg_InvalidSearchPattern"));
if ((searchPattern[index+2] == DirectorySeparatorChar)
|| (searchPattern[index+2] == AltDirectorySeparatorChar))
throw new ArgumentException(Environment.GetResourceString("Arg_InvalidSearchPattern"));
searchPattern = searchPattern.Substring(index + 2);
}
}
示例14: CheckForRedirectedClientType
} // CheckForWellKnownServiceEntryOfType
// returns true if activation for the type has been redirected.
private bool CheckForRedirectedClientType(String typeName, String asmName)
{
// if asmName has version information, remove it.
int index = asmName.IndexOf(",");
if (index != -1)
asmName = asmName.Substring(0, index);
return
(QueryRemoteActivate(typeName, asmName) != null) ||
(QueryConnect(typeName, asmName) != null);
} // CheckForRedirectedClientType
示例15: GetEmbededNullStringLengthAnsi
private static int GetEmbededNullStringLengthAnsi(String s) {
int n = s.IndexOf('\0');
if (n > -1) {
String left = s.Substring(0, n);
String right = s.Substring(n+1);
return GetPInvokeStringLength(left) + GetEmbededNullStringLengthAnsi(right) + 1;
}
else {
return GetPInvokeStringLength(s);
}
}