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


C# String.indexOf方法代码示例

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


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

示例1: parseVerboseInt

 		private int parseVerboseInt(String input) {
 			String loadedString = String.format("%s", input);
 			boolean negative = false;
 			int base = 10;
 			int shift = 3;
 			int retVal = -1;
 			if (input.charAt(0) == '-') {
 				negative = true;
 				input = input.substring(1);
 			}
 			if (input.indexOf("0x") == 0) {
 				base = 16;
 				input = input.substring(2);
 			}
 			if (input.indexOf("b") == input.length() - 1) {
 				shift = 0;
 				input = input.substring(0, input.length() - 1);
 			}
 			try {
 				retVal = Integer.parseInt(input, base);
 			} catch (Exception e) {
 				addGeneralError(loadedString);
 				validComponent = false;
 			}
 			if (validComponent) {
 				retVal <<= shift;
 				if (negative)
 					retVal = 0 - retVal;
 			}
 			return retVal;
 		}
开发者ID:Crazycolorz5,项目名称:FEEditorSuite2015ProDeluxeEdition,代码行数:31,代码来源:NightmareModule.cs

示例2: canonicalizePath

        /**
         * Canonicalize the path, i.e. remove ".." and "." occurences.
         *
         * @param path the path to be canonicalized
         * @return the canonicalized path
         */
        public static String canonicalizePath(String path)
        {
            int dirIndex;

            while ((dirIndex = path.indexOf("/./")) >= 0)
            { //$NON-NLS-1$
                path = path.substring(0, dirIndex + 1)
                        + path.substring(dirIndex + 3);
            }

            if (path.endsWith("/."))
            { //$NON-NLS-1$
                path = path.substring(0, path.length() - 1);
            }

            while ((dirIndex = path.indexOf("/../")) >= 0)
            { //$NON-NLS-1$
                if (dirIndex != 0)
                {
                    path = path.substring(0, path
                            .lastIndexOf('/', dirIndex - 1))
                            + path.substring(dirIndex + 3);
                }
                else
                {
                    path = path.substring(dirIndex + 3);
                }
            }

            if (path.endsWith("/..") && path.length() > 3)
            { //$NON-NLS-1$
                path = path.substring(0, path.lastIndexOf('/',
                        path.length() - 4) + 1);
            }
            return path;
        }
开发者ID:sailesh341,项目名称:JavApi,代码行数:42,代码来源:URLUtil.cs

示例3: quoteIllegal

        internal const String encoding = "utf-8"; //$NON-NLS-1$

        #endregion Fields

        #region Methods

        /**
         * All characters except letters ('a'..'z', 'A'..'Z') and numbers ('0'..'9')
         * and legal characters are converted into their hexidecimal value prepended
         * by '%'.
         * <p>
         * For example: '#' -> %23
         * Other characters, which are unicode chars that are not US-ASCII, and are
         * not ISO Control or are not ISO Space chars, are preserved.
         * <p>
         * Called from {@code URI.quoteComponent()} (for multiple argument
         * constructors)
         *
         * @param s
         *            java.lang.String the string to be converted
         * @param legal
         *            java.lang.String the characters allowed to be preserved in the
         *            string s
         * @return java.lang.String the converted string
         */
        internal static String quoteIllegal(String s, String legal)
        {
            //throws UnsupportedEncodingException {
            StringBuilder buf = new StringBuilder();
            for (int i = 0; i < s.length(); i++) {
                char ch = s.charAt(i);
                if ((ch >= 'a' && ch <= 'z')
                        || (ch >= 'A' && ch <= 'Z')
                        || (ch >= '0' && ch <= '9')
                        || legal.indexOf(ch) > -1
                        || (ch > 127 && !java.lang.Character.isSpaceChar(ch) && !java.lang.Character
                                .isISOControl(ch))) {
                    buf.append(ch);
                } else {
                    byte[] bytes = new String(new char[] { ch }).getBytes(encoding);
                    for (int j = 0; j < bytes.Length; j++) {
                        buf.append('%');
                        buf.append(digits.charAt((bytes[j] & 0xf0) >> 4));
                        buf.append(digits.charAt(bytes[j] & 0xf));
                    }
                }
            }
            return buf.toString();
        }
开发者ID:gadfly,项目名称:nofs,代码行数:49,代码来源:java.net.URIEncoderDecoder.cs

示例4: convertPattern

 protected internal virtual String convertPattern(String template, String fromChars, String toChars,
         bool check)
 {
     if (!check && fromChars.equals(toChars)) {
         return template;
     }
     bool quote = false;
     StringBuilder output = new StringBuilder();
     int length = template.length();
     for (int i = 0; i < length; i++) {
         int index;
         char next = template.charAt(i);
         if (next == '\'') {
             quote = !quote;
         }
         if (!quote && (index = fromChars.indexOf(next)) != -1) {
             output.append(toChars.charAt(index));
         } else if (check
                 && !quote
                 && ((next >= 'a' && next <= 'z') || (next >= 'A' && next <= 'Z'))) {
             // text.05=Invalid pattern char {0} in {1}
             throw new java.lang.IllegalArgumentException("Invalid pattern char "+next+" in "+ template); //$NON-NLS-1$
         } else {
             output.append(next);
         }
     }
     if (quote) {
         // text.04=Unterminated quote
         throw new java.lang.IllegalArgumentException("Unterminated quote"); //$NON-NLS-1$
     }
     return output.toString();
 }
开发者ID:sailesh341,项目名称:JavApi,代码行数:32,代码来源:Format.cs

示例5: getHostFromUrl

        static String getHostFromUrl( String strUrl )
        {
            int nHttp = strUrl.indexOf("://");
            if ( nHttp < 0 )
                nHttp = strUrl.indexOf(":\\\\");

            int nStartSrv = 0;
            if ( nHttp >= 0 )
                nStartSrv = nHttp + 3;

            int nEndSrv = strUrl.indexOf('/', nStartSrv);
            if ( nEndSrv < 0 )
                nEndSrv = strUrl.indexOf('\\', nStartSrv);

            int nSrvLen = nEndSrv >= 0 ? nEndSrv + 1 : strUrl.length();
            return strUrl.substring(nSrvLen);
        }    
开发者ID:rrmartins,项目名称:rhodes,代码行数:17,代码来源:SyncEngine.cs

示例6: parseFileName

        /**
         * Transform the pattern to the valid file name, replacing any patterns, and
         * applying generation and uniqueID if present
         *
         * @param gen
         *            generation of this file
         * @return transformed filename ready for use
         */
        private String parseFileName(int gen)
        {
            int cur = 0;
            int next = 0;
            bool hasUniqueID = false;
            bool hasGeneration = false;

            // TODO privilege code?
            String homePath = java.lang.SystemJ.getProperty("user.home"); //$NON-NLS-1$
            if (homePath == null) {
            throw new java.lang.NullPointerException();
            }
            bool homePathHasSepEnd = homePath.endsWith(java.io.File.separator);

            String tempPath = java.lang.SystemJ.getProperty("java.io.tmpdir"); //$NON-NLS-1$
            tempPath = tempPath == null ? homePath : tempPath;
            bool tempPathHasSepEnd = tempPath.endsWith(java.io.File.separator);

            java.lang.StringBuilder sb = new java.lang.StringBuilder();
            pattern = pattern.replace('/', java.io.File.separatorChar);

            char[] value = pattern.toCharArray();
            while ((next = pattern.indexOf('%', cur)) >= 0) {
            if (++next < pattern.length()) {
                switch (value[next]) {
                    case 'g':
                        sb.append(value, cur, next - cur - 1).append(gen);
                        hasGeneration = true;
                        break;
                    case 'u':
                        sb.append(value, cur, next - cur - 1).append(uniqueID);
                        hasUniqueID = true;
                        break;
                    case 't':
                        /*
                         * we should probably try to do something cute here like
                         * lookahead for adjacent '/'
                         */
                        sb.append(value, cur, next - cur - 1).append(tempPath);
                        if (!tempPathHasSepEnd) {
                            sb.append(java.io.File.separator);
                        }
                        break;
                    case 'h':
                        sb.append(value, cur, next - cur - 1).append(homePath);
                        if (!homePathHasSepEnd) {
                            sb.append(java.io.File.separator);
                        }
                        break;
                    case '%':
                        sb.append(value, cur, next - cur - 1).append('%');
                        break;
                    default:
                        sb.append(value, cur, next - cur);
                        break;
                }
                cur = ++next;
            } else {
                // fail silently
            }
            }

            sb.append(value, cur, value.Length - cur);

            if (!hasGeneration && count > 1) {
            sb.append(".").append(gen); //$NON-NLS-1$
            }

            if (!hasUniqueID && uniqueID > 0) {
            sb.append(".").append(uniqueID); //$NON-NLS-1$
            }

            return sb.toString();
        }
开发者ID:sailesh341,项目名称:JavApi,代码行数:82,代码来源:FileHandler.cs

示例7: URI

        /**
         * Creates a new URI instance using the given arguments. This constructor
         * first creates a temporary URI string from the given components. This
         * string will be parsed later on to create the URI instance.
         * <p/>
         * {@code [scheme:][[email protected]]host[:port][path][?query][#fragment]}
         *
         * @param scheme
         *            the scheme part of the URI.
         * @param userinfo
         *            the user information of the URI for authentication and
         *            authorization.
         * @param host
         *            the host name of the URI.
         * @param port
         *            the port number of the URI.
         * @param path
         *            the path to the resource on the host.
         * @param query
         *            the query part of the URI to specify parameters for the
         *            resource.
         * @param fragment
         *            the fragment part of the URI.
         * @throws URISyntaxException
         *             if the temporary created string doesn't fit to the
         *             specification RFC2396 or could not be parsed correctly.
         */
        public URI(String scheme, String userinfo, String host, int port,
                String path, String query, String fragment)
        {
            //throws URISyntaxException {
            StringBuilder uri = new StringBuilder();
            try {

                if (scheme == null && userinfo == null && host == null && path == null
                        && query == null && fragment == null) {
                delegateInstance = new Uri (uri.ToString());
                    return;
                }

                if (scheme != null && path != null && path.length() > 0
                        && path.charAt(0) != '/') {
                    throw new URISyntaxException(path, "Relative path"); //$NON-NLS-1$
                }

                if (scheme != null) {
                    uri.append(scheme);
                    uri.append(':');
                }

                if (userinfo != null || host != null || port != -1) {
                    uri.append("//"); //$NON-NLS-1$
                }

                if (userinfo != null) {
                    // QUOTE ILLEGAL CHARACTERS in userinfo
                    uri.append(quoteComponent(userinfo, someLegal));
                    uri.append('@');
                }

                if (host != null) {
                    // check for ipv6 addresses that hasn't been enclosed
                    // in square brackets
                    if (host.indexOf(':') != -1 && host.indexOf(']') == -1
                            && host.indexOf('[') == -1) {
                        host = "[" + host + "]"; //$NON-NLS-1$ //$NON-NLS-2$
                    }
                    uri.append(host);
                }

                if (port != -1) {
                    uri.append(':');
                    uri.append(port);
                }

                if (path != null) {
                    // QUOTE ILLEGAL CHARS
                    uri.append(quoteComponent(path, "/@" + someLegal)); //$NON-NLS-1$
                }

                if (query != null) {
                    uri.append('?');
                    // QUOTE ILLEGAL CHARS
                    uri.append(quoteComponent(query, allLegal));
                }

                if (fragment != null) {
                    // QUOTE ILLEGAL CHARS
                    uri.append('#');
                    uri.append(quoteComponent(fragment, allLegal));
                }
                delegateInstance = new Uri (uri.ToString());
            }
            catch (ArgumentNullException ane) {
                throw new java.lang.NullPointerException(ane.getMessage());
            }
            catch (UriFormatException ufe) {
                throw new URISyntaxException (uri.ToString(),ufe.Message);
            }
        }
开发者ID:sailesh341,项目名称:JavApi,代码行数:100,代码来源:URI.cs

示例8: getProviders

 /**
  * Returns the array of providers which meet the user supplied string
  * filter. The specified filter must be supplied in one of two formats:
  * <nl>
  * <li> CRYPTO_SERVICE_NAME.ALGORITHM_OR_TYPE</li>
  * <p/>
  * (for example: "MessageDigest.SHA")
  * <li> CRYPTO_SERVICE_NAME.ALGORITHM_OR_TYPE</li>
  * ATTR_NAME:ATTR_VALUE
  * <p/>
  * (for example: "Signature.MD2withRSA KeySize:512")
  * </nl>
  *
  * @param filter
  *            case-insensitive filter.
  * @return the providers which meet the user supplied string filter {@code
  *         filter}. A {@code null} value signifies that none of the
  *         installed providers meets the filter specification.
  * @throws InvalidParameterException
  *             if an unusable filter is supplied.
  * @throws NullPointerException
  *             if {@code filter} is {@code null}.
  */
 public static Provider[] getProviders(String filter)
 {
     if (filter == null)
     {
         throw new java.lang.NullPointerException("The filter is null"); //$NON-NLS-1$
     }
     if (filter.length() == 0)
     {
         throw new InvalidParameterException("The filter is not in the required format"); //$NON-NLS-1$
     }
     java.util.HashMap<String, String> hm = new java.util.HashMap<String, String>();
     int i = filter.indexOf(':');
     if ((i == filter.length() - 1) || (i == 0))
     {
         throw new InvalidParameterException("The filter is not in the required format"); //$NON-NLS-1$
     }
     if (i < 1)
     {
         hm.put(filter, ""); //$NON-NLS-1$
     }
     else
     {
         hm.put(filter.substring(0, i), filter.substring(i + 1));
     }
     return getProviders(hm);
 }
开发者ID:sailesh341,项目名称:JavApi,代码行数:49,代码来源:Security.cs

示例9: parseLine

        /// <summary>
        /// Internal helper method for parsing INFO files line by line.
        /// </summary>
        ///
        private BoostInfoTree parseLine(String line, BoostInfoTree context)
        {
            // Skip blank lines and comments.
            int commentStart = line.indexOf(';');
            if (commentStart >= 0)
                line = line.Substring(0,(commentStart)-(0)).trim();
            if (line.Length == 0)
                return context;

            // Usually we are expecting key and optional value.
            // Use ArrayList without generics so it works with older Java compilers.
            ArrayList<String> strings = new ArrayList<String>();
            shlex_split(line, strings);
            bool isSectionStart = false;
            bool isSectionEnd = false;
            for (int i = 0; i < strings.Count; ++i) {
                isSectionStart = (isSectionStart || "{".equals(strings[i]));
                isSectionEnd = (isSectionEnd || "}".equals(strings[i]));
            }

            if (!isSectionStart && !isSectionEnd) {
                String key = strings[0];
                String val = "";
                if (strings.Count > 1)
                    val = strings[1];

                // If it is an "#include", load the new file instead of inserting keys.
                if ("#include".equals(key)) {
                    TextReader stream = new FileReader(val);
                    // Use "try/finally instead of "try-with-resources" or "using"
                    // which are not supported before Java 7.
                    try {
                        context = read(stream, context);
                    } finally {
                        stream.close();
                    }
                } else
                    context.createSubtree(key, val);

                return context;
            }

            // OK, who is the joker who put a { on the same line as the key name?!
            int sectionStart = line.indexOf('{');
            if (sectionStart > 0) {
                String firstPart = line.Substring(0,(sectionStart)-(0));
                String secondPart = line.Substring(sectionStart);

                BoostInfoTree ctx = parseLine(firstPart, context);
                return parseLine(secondPart, ctx);
            }

            // If we encounter a {, we are beginning a new context.
            // TODO: Error if there was already a subcontext here.
            if (line[0] == '{') {
                context = context.getLastChild();
                return context;
            }

            // If we encounter a }, we are ending a list context.
            if (line[0] == '}') {
                context = context.getParent();
                return context;
            }

            throw new Exception("BoostInfoParser: input line is malformed");
        }
开发者ID:named-data,项目名称:ndn-dot-net,代码行数:71,代码来源:BoostInfoParser.cs

示例10: AbstractPreferences

 /*
  * ----------------------------------------------------------- Constructors
  * -----------------------------------------------------------
  */
 /**
  * Constructs a new {@code AbstractPreferences} instance using the given
  * parent node and node name.
  *
  * @param parent
  *            the parent node of the new node or {@code null} to indicate
  *            that the new node is a root node.
  * @param name
  *            the name of the new node or an empty string to indicate that
  *            this node is called "root".
  * @throws IllegalArgumentException
  *             if the name contains a slash character or is empty if {@code
  *             parent} is not {@code null}.
  */
 protected AbstractPreferences(AbstractPreferences parent, String name)
 {
     if ((null == parent ^ name.length() == 0) || name.indexOf("/") >= 0) { //$NON-NLS-1$
     throw new java.lang.IllegalArgumentException();
     }
     root = null == parent ? this : parent.root;
     nodeChangeListeners = new LinkedList<EventListener>();
     preferenceChangeListeners = new LinkedList<EventListener>();
     isRemovedJ = false;
     cachedNode = new HashMap<String, AbstractPreferences>();
     nodeName = name;
     parentPref = parent;
     lockJ = new Lock();
     userNode = root.userNode;
 }
开发者ID:sailesh341,项目名称:JavApi,代码行数:33,代码来源:AbstractPreferences.cs

示例11: validate

        /**
         * Validate a string by checking if it contains any characters other than:
         * 1. letters ('a'..'z', 'A'..'Z') 2. numbers ('0'..'9') 3. characters in
         * the legalset parameter 4. others (unicode characters that are not in
         * US-ASCII set, and are not ISO Control or are not ISO Space characters)
         * <p>
         * called from {@code URI.Helper.parseURI()} to validate each component
         *
         * @param s
         *            {@code java.lang.String} the string to be validated
         * @param legal
         *            {@code java.lang.String} the characters allowed in the String
         *            s
         */
        internal static void validate(String s, String legal)
        {
            // throws URISyntaxException {
            for (int i = 0; i < s.length();) {
                char ch = s.charAt(i);
                if (ch == '%') {
                    do {
                        if (i + 2 >= s.length()) {
                            throw new URISyntaxException(s, "Incomplete % sequence",i);
                        }
                        int d1 = java.lang.Character.digit(s.charAt(i + 1), 16);
                        int d2 = java.lang.Character.digit(s.charAt(i + 2), 16);
                        if (d1 == -1 || d2 == -1) {
                            throw new URISyntaxException(s, "Invalid % sequence ("+s.substring(i, i + 3)+")",i);
                        }

                        i += 3;
                    } while (i < s.length() && s.charAt(i) == '%');

                    continue;
                }
                if (!((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')
                        || (ch >= '0' && ch <= '9') || legal.indexOf(ch) > -1 || (ch > 127
                        && !java.lang.Character.isSpaceChar(ch) && !java.lang.Character
                        .isISOControl(ch)))) {
                    throw new URISyntaxException(s, "Illegal character", i); //$NON-NLS-1$
                }
                i++;
            }
        }
开发者ID:gadfly,项目名称:nofs,代码行数:44,代码来源:java.net.URIEncoderDecoder.cs

示例12: validateSimple

 internal static void validateSimple(String s, String legal)
 {
     //throws URISyntaxException {
     for (int i = 0; i < s.length();) {
         char ch = s.charAt(i);
         if (!((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')
                 || (ch >= '0' && ch <= '9') || legal.indexOf(ch) > -1)) {
             throw new URISyntaxException(s, "Illegal character", i); //$NON-NLS-1$
         }
         i++;
     }
 }
开发者ID:gadfly,项目名称:nofs,代码行数:12,代码来源:java.net.URIEncoderDecoder.cs

示例13: pathFromUrl

 private String pathFromUrl(String url)
 {
     if (0 == url.IndexOf(REQUEST_URL_SCHEME_PREFIX))
     {
         return url.substring(url.indexOf(":") + 1);
     }
     return url;
 }
开发者ID:JerryFLane,项目名称:rhodes,代码行数:8,代码来源:RhoView.xaml.cs

示例14: valueOf

 /**
  * Creates a {@code Date} from a string representation of a date in SQL
  * format.
  *
  * @param dateString
  *            the string representation of a date in SQL format - " {@code
  *            yyyy-mm-dd}".
  * @return the {@code Date} object.
  * @throws IllegalArgumentException
  *             if the format of the supplied string does not match the SQL
  *             format.
  */
 public static Date valueOf(String dateString)
 {
     if (dateString == null)
     {
         throw new java.lang.IllegalArgumentException();
     }
     int firstIndex = dateString.indexOf('-');
     int secondIndex = dateString.indexOf('-', firstIndex + 1);
     // secondIndex == -1 means none or only one separator '-' has been
     // found.
     // The string is separated into three parts by two separator characters,
     // if the first or the third part is null string, we should throw
     // IllegalArgumentException to follow RI
     if (secondIndex == -1 || firstIndex == 0
             || secondIndex + 1 == dateString.length())
     {
         throw new java.lang.IllegalArgumentException();
     }
     // parse each part of the string
     int year = java.lang.Integer.parseInt(dateString.substring(0, firstIndex));
     int month = java.lang.Integer.parseInt(dateString.substring(firstIndex + 1,
             secondIndex));
     int day = java.lang.Integer.parseInt(dateString.substring(secondIndex + 1,
             dateString.length()));
     return new Date(year - 1900, month - 1, day);
 }
开发者ID:sailesh341,项目名称:JavApi,代码行数:38,代码来源:Date.cs

示例15: valueOf

 /**
  * Creates a {@code Time} object from a string holding a time represented in
  * JDBC escape format: {@code hh:mm:ss}.
  * <p/>
  * An exception occurs if the input string does not comply with this format.
  *
  * @param timeString
  *            A String representing the time value in JDBC escape format:
  *            {@code hh:mm:ss}.
  * @return The {@code Time} object set to a time corresponding to the given
  *         time.
  * @throws IllegalArgumentException
  *             if the supplied time string is not in JDBC escape format.
  */
 public static Time valueOf(String timeString)
 {
     if (timeString == null)
     {
         throw new java.lang.IllegalArgumentException();
     }
     int firstIndex = timeString.indexOf(':');
     int secondIndex = timeString.indexOf(':', firstIndex + 1);
     // secondIndex == -1 means none or only one separator '-' has been
     // found.
     // The string is separated into three parts by two separator characters,
     // if the first or the third part is null string, we should throw
     // IllegalArgumentException to follow RI
     if (secondIndex == -1 || firstIndex == 0
             || secondIndex + 1 == timeString.length())
     {
         throw new java.lang.IllegalArgumentException();
     }
     // parse each part of the string
     int hour = java.lang.Integer.parseInt(timeString.substring(0, firstIndex));
     int minute = java.lang.Integer.parseInt(timeString.substring(firstIndex + 1,
             secondIndex));
     int second = java.lang.Integer.parseInt(timeString.substring(secondIndex + 1,
             timeString.length()));
     return new Time(hour, minute, second);
 }
开发者ID:sailesh341,项目名称:JavApi,代码行数:40,代码来源:Time.cs


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